parse-argv 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/lib/parse_argv.rb ADDED
@@ -0,0 +1,3 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative 'parse-argv'
data/syntax.md ADDED
@@ -0,0 +1,158 @@
1
+ # ParseArgv Syntax
2
+
3
+ - [Help Text Syntax](#help-text-syntax)
4
+ - [Command Line Syntax](#command-line-syntax)
5
+
6
+ ## Help Text Syntax
7
+
8
+ A help text must follow these simple rules:
9
+
10
+ • All help text should be designed to be presented to the user as command line help.
11
+
12
+ • A command is recognized by a line with the following pattern:
13
+ ```
14
+ usage: command
15
+ ```
16
+
17
+ • A subcommand is recognized by a line with the following pattern:
18
+ ```
19
+ usage: command subcommand
20
+ ```
21
+
22
+ • Command line arguments must be enclosed with less-than/greater-than characters (`<` and `>`).
23
+ ```
24
+ usage: command <argument>
25
+ ```
26
+
27
+ • Optional arguments are enclosed in square brackets (`[` and `]`).
28
+ ```
29
+ usage: command [<argument>]
30
+ ```
31
+
32
+ • Arguments to be collected in arrays are marked with three dots at the end.
33
+ ```
34
+ usage: command <argument>...
35
+ ```
36
+ ```
37
+ usage: command [<argument>...]
38
+ ```
39
+
40
+ • Options start after any number of spaces with a stroke (`-`) and a single letter, or two strokes (`--`)and a word, which must be followed by a descriptive text.
41
+ ```
42
+ -s this is a boolean option (switch)
43
+ ```
44
+ ```
45
+ --switch this is a boolean option (switch)
46
+ ```
47
+
48
+ • Options that are to be specified both as a word and its abbreviation can be combined with a comma (`,`).
49
+ ```
50
+ -s, --switch this is a boolean option (switch)
51
+ ```
52
+
53
+ • Options that require an argument additionally define the name of the argument after the declaration, enclosed with less-than/greater-than characters (`<` and `>`).
54
+ ```
55
+ -o <option> this is an option with the argument named "option"
56
+ ```
57
+ ```
58
+ --opt <option> this is an option with the argument named "option"
59
+ ```
60
+ ```
61
+ -o, --opt <option> this is an option with the argument named "option"
62
+ ```
63
+
64
+ • If multiple subcommands are to be defined (git-like commands), the individual commands can be separated with a line beginning with a `#` character.
65
+ ```
66
+ usage: command
67
+ Options and helptext for "command" here...
68
+
69
+ #
70
+
71
+ This is the help text header for the subcommand
72
+
73
+ usage: command subcommand
74
+ Options and helptext for the subcommand here...
75
+ ```
76
+
77
+ ## Command Line Syntax
78
+
79
+ ### Simple Arguments
80
+
81
+ A command line program using ParseArgv accepts all required and optional parameters as expected. The user will be notified of missing or excess parameters, if any.
82
+
83
+ Definition example:
84
+
85
+ ```
86
+ usage: sample <infile> [<template>] <outfile>
87
+ ```
88
+
89
+ The `<infile>` and `<outfile>` parameters are required. If they are not specified, the user will be notified.
90
+
91
+ ```shell
92
+ sample ./source.md ./out.html
93
+ # ok, infile: "./source.md", outfile: "./out.html"
94
+
95
+ sample ./source.md
96
+ # error: "sample: argument missing - <outfile>"
97
+ ```
98
+
99
+ If three parameters are specified in this example, the optional third parameter is also accepted.
100
+
101
+ ```shell
102
+ sample ./source.md ./template.yaml ./out.html
103
+ # ok, infile: "./source.md", template: "./template.yaml", outfile: "./out.html"
104
+ ```
105
+
106
+ If too many parameters are specified, the user will be notified.
107
+
108
+ ```shell
109
+ sample ./source.md ./template.yaml ./out.html ./some.txt
110
+ # error: "sample: too many arguments"
111
+ ```
112
+
113
+ ### Options
114
+
115
+ Consider the following definition example:
116
+
117
+ ```
118
+ usage: sample <infile>
119
+
120
+ options:
121
+ -o, --out <outfile> specify output file name
122
+ -t, --template <template> use given template
123
+ -c. --colors enable color mode
124
+ -v, --verbose enable verbose mode
125
+ ```
126
+
127
+ Here the user must specify a `<infile>` parameter, can add optional (named) arguments (`<outfile>` and `<template>`) and select parameterless options (`<colors>` and `verbose`).
128
+
129
+ Since `<infile>`is a required argument, it must always be specified, all other specifications are optional.
130
+
131
+ ```shell
132
+ sample ./source.md
133
+ # ok, infile: "./source.md"
134
+
135
+ sample ./source.md --out ./result.html -c
136
+ # ok, infile: "./source.md", outfile: "./result.html", colors: true
137
+ ```
138
+
139
+ The short forms of the options can also be combined.
140
+
141
+ ```shell
142
+ sample ./source.md -voc ./result.html
143
+ # ok, infile: "./source.md", outfile: "./result.html", colors: true, verbose: true
144
+ ```
145
+
146
+ To write down the affiliation of named parameters more clearly, the following notation is allowed.
147
+
148
+ ```shell
149
+ sample ./source.md --out:./result.html -t=nice.yaml
150
+ # ok, infile: "./source.md", outfile: "./result.html", template: "nice.yaml"
151
+ ```
152
+
153
+ Parameterless options can be understood as switches. Therefore it is possible to write them down like this:
154
+
155
+ ```shell
156
+ sample ./source.md --colors:on -v:off
157
+ # ok, infile: "./source.md", colors: true, verbose: false
158
+ ```
metadata ADDED
@@ -0,0 +1,70 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: parse-argv
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Mike Blumtritt
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2022-11-26 00:00:00.000000000 Z
12
+ dependencies: []
13
+ description: |
14
+ Just write the help text for your application and ParseArgv will take care
15
+ of your command line. It works sort of the other way around than OptParse,
16
+ where you write a lot of code to get a command line parser and generated
17
+ help text. ParseArgv simply takes your help text and parses the command
18
+ line and presents you the results.
19
+
20
+ You can use ParseArgv for simpler programs just as well as for CLI with
21
+ multi-level sub-commands (git-like commands). ParseArgv is easy to use,
22
+ fast and also helps you convert the data types of command line arguments.
23
+ email:
24
+ executables: []
25
+ extensions: []
26
+ extra_rdoc_files:
27
+ - ReadMe.md
28
+ - syntax.md
29
+ - LICENSE
30
+ files:
31
+ - ".yardopts"
32
+ - LICENSE
33
+ - ReadMe.md
34
+ - examples/ReadMe.md
35
+ - examples/check.rb
36
+ - examples/conversion.rb
37
+ - examples/multi.rb
38
+ - examples/simple.rb
39
+ - lib/parse-argv.rb
40
+ - lib/parse-argv/conversion.rb
41
+ - lib/parse-argv/version.rb
42
+ - lib/parse_argv.rb
43
+ - syntax.md
44
+ homepage: https://github.com/mblumtritt/parse-argv
45
+ licenses:
46
+ - BSD-3-Clause
47
+ metadata:
48
+ source_code_uri: https://github.com/mblumtritt/parse-argv
49
+ bug_tracker_uri: https://github.com/mblumtritt/parse-argv/issues
50
+ documentation_uri: https://rubydoc.info/gems/parse-argv
51
+ post_install_message:
52
+ rdoc_options: []
53
+ require_paths:
54
+ - lib
55
+ required_ruby_version: !ruby/object:Gem::Requirement
56
+ requirements:
57
+ - - ">="
58
+ - !ruby/object:Gem::Version
59
+ version: 2.7.0
60
+ required_rubygems_version: !ruby/object:Gem::Requirement
61
+ requirements:
62
+ - - ">="
63
+ - !ruby/object:Gem::Version
64
+ version: '0'
65
+ requirements: []
66
+ rubygems_version: 3.3.26
67
+ signing_key:
68
+ specification_version: 4
69
+ summary: A command line parser that only needs your help text.
70
+ test_files: []