1.0.93 • Published 4 years ago

sg-argv v1.0.93

Weekly downloads
3
License
MIT
Repository
github
Last release
4 years ago

sg-argv

Command-line argument parsing.

Parse CLI Arguments for Easy Use in Javascript

Usage

npm install sg-argv

Then

const sg      = require('sg-argv');

// ...

const ARGV    = sg.ARGV();

if (ARGV.fooBar) {
  // ...
}

sg-argv will analyze process.argv, and build JSON, and be reasonably intelligent about it.

Run the see.js script in the root of the sg-argv repo, and see what converts to what.

$ node see.js cmd \
    --multi-seg-opt=55 \
    --flag \
    --opt=val \
    --arr= one two three \
    --json={"a":42} \
    --json2={'foo':'bar'} \
    --bad- \
    --no-op2 \
    --re=/^[a-z]+/ \
    --date=2019-11-25T04:07:23.314Z \
    --package=@package.json \
    --license=@LICENSE

=>

              arr       Array     ["one","two","three"]
              bad     boolean                     false
              op2     boolean                     false
                _       Array                   ["cmd"]
    multi-seg-opt      number                        55
             flag     boolean                      true
              opt      string                     "val"
             json      object                  {"a":42}
            json2      object             {"foo":"bar"}
               re      RegExp                 /^[a-z]+/
            debug     boolean                      true
    multi_seg_opt      number                        55
      multiSegOpt      number                        55
         _command      string                     "cmd"

             date        Date     Sun Nov 24 2019 20:07:23 GMT-0800 (Pacific Standard Time)

          package      object {"name":"sg-argv","version":"1.0.73","description":"Parameter parsing.","main":"...
          license      string "MIT License\nCopyright (c) 2016 Brian C Sparks\nPermission is hereby granted, f...
  • Provides snake-case and camel-case versions of the keys, because this-is-not a dottable key on an object.
  • Parses the values in a smart, but not too smart, way.
  • Provides a few extension functions if you need to do more.
  • Provides versions that produce only POD results.

It will convert the following:

  • Items that are all digits are converted to Numbers.
  • Items that have all digits, except one dot, are also converted to Numbers.
  • true, false, and null, are converted to true, false, and null.
  • Dates in the format: 2018-12-31T10:08:56.016Z are converted to Dates.
  • Items that start and end with / are converted to RegExps.
  • JSON is read and parsed as JSON.
  • JSON that has single-quotes in place of double quotes is read, has the single-quotes turned into double-quotes and is parsed as JSON.
    • The conversion is a straight one-to-one conversion, nothing intelligent is done.

And:

  • --items-like-this= a b c will be read as Arrays.
    • {itemsLikeThis: ['a', 'b', 'c'], _: []}
  • --items-like-this=a b c is a string and parameters.
    • {itemsLikeThis: 'a', _: ['b', 'c']}
  • --file=@path/to/file is read in from a file (becomes a string).
  • --file=@path/to/file.json is read in from a file (parsed as JSON).
  • --negative-opt- is one way to say false: {negativeOpt: false}
  • --no-cheese is another way to say false: {cheese: false}
1.0.93

4 years ago

1.0.92

4 years ago

1.0.88

4 years ago

1.0.90

4 years ago

1.0.87

4 years ago

1.0.86

4 years ago

1.0.85

4 years ago

1.0.84

4 years ago

1.0.83

4 years ago

1.0.82

4 years ago

1.0.80

4 years ago

1.0.81

4 years ago

1.0.79

4 years ago

1.0.77

4 years ago

1.0.78

4 years ago

1.0.76

4 years ago

1.0.75

4 years ago

1.0.74

4 years ago

1.0.73

4 years ago

1.0.71

4 years ago

1.0.70

4 years ago

1.0.69

4 years ago

1.0.68

4 years ago

1.0.67

4 years ago

1.0.66

4 years ago

1.0.65

5 years ago

1.0.64

5 years ago

1.0.63

5 years ago

1.0.62

5 years ago

1.0.61

5 years ago

1.0.60

5 years ago

1.0.59

5 years ago

1.0.58

5 years ago

1.0.57

5 years ago

1.0.56

5 years ago

1.0.55

5 years ago

1.0.54

5 years ago

1.0.53

5 years ago

1.0.52

5 years ago

1.0.51

5 years ago

1.0.50

5 years ago

1.0.49

5 years ago

1.0.48

5 years ago

1.0.47

5 years ago

1.0.46

5 years ago

1.0.45

5 years ago

1.0.44

5 years ago

1.0.43

5 years ago

1.0.42

5 years ago

1.0.41

5 years ago

1.0.40

5 years ago

1.0.39

5 years ago

1.0.37

5 years ago

1.0.36

5 years ago

1.0.35

5 years ago

1.0.34

5 years ago

1.0.33

5 years ago

1.0.32

5 years ago

1.0.31

5 years ago

1.0.30

5 years ago

1.0.29

5 years ago

1.0.28

5 years ago

1.0.27

5 years ago

1.0.26

5 years ago

1.0.25

5 years ago

1.0.24

5 years ago

1.0.23

5 years ago

1.0.22

5 years ago

1.0.21

5 years ago

1.0.20

5 years ago

1.0.19

5 years ago

1.0.18

5 years ago

1.0.17

5 years ago

1.0.16

5 years ago

1.0.15

5 years ago

1.0.14

5 years ago

1.0.13

5 years ago

1.0.12

5 years ago

1.0.11

5 years ago

1.0.10

5 years ago

1.0.9

5 years ago

1.0.8

5 years ago

1.0.7

5 years ago

1.0.6

5 years ago

1.0.5

5 years ago

1.0.4

5 years ago

1.0.3

5 years ago

1.0.2

5 years ago

1.0.1

5 years ago

0.9.13

5 years ago

0.9.12

5 years ago

0.9.11

5 years ago

0.9.10

5 years ago

0.9.9

5 years ago

0.9.8

5 years ago

0.9.7

5 years ago

0.9.5

5 years ago

0.9.4

5 years ago