argvise 0.0.4 → 0.0.5
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.
- checksums.yaml +4 -4
- data/docs/Readme.md +31 -28
- data/lib/argvise/version.rb +1 -1
- data/lib/core.rb +22 -8
- metadata +1 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: cc2e3625fabe3294535d920c085b82f1c2718032de5f3921a7a9f74424c1ca5f
|
|
4
|
+
data.tar.gz: 2005628bc2fc53ea8937a310111b4217289051e3c634d5960287ed9e4db4dca0
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 1f78e1ea42b3d355ec65da36c69bbf31b7dfa7386c7483ed42c625ef15dc826f052e7009f040a47ef0f685a2f4d26de347edfeeba9c53c09cdb7941bc5b6915a
|
|
7
|
+
data.tar.gz: a9c6c99a0590f822f5dda6782a3a12c664008c8eff472c234f004e9b2fb69033e12dba58d8efd6c9bb77ec449cc97dab121cf875e80535f226f0ec29c3aea45c
|
data/docs/Readme.md
CHANGED
|
@@ -2,6 +2,8 @@
|
|
|
2
2
|
|
|
3
3
|
[](https://rubygems.org/gems/argvise)
|
|
4
4
|
|
|
5
|
+
<!-- [](https://www.rubydoc.info/gems/argvise) -->
|
|
6
|
+
|
|
5
7
|
A Ruby gem for converting hash structures into command-line argument arrays.
|
|
6
8
|
|
|
7
9
|
> **Note:** This is *not* a command-line parser — quite the opposite. Argvise helps you **build** CLI commands programmatically.
|
|
@@ -17,16 +19,16 @@ system "gem install argvise"
|
|
|
17
19
|
# RUBY
|
|
18
20
|
require 'argvise'
|
|
19
21
|
|
|
20
|
-
{ cargo: nil,
|
|
22
|
+
{ cargo: nil, b: nil, r: true, target: "wasm32-wasip2" }
|
|
21
23
|
.then(&hash_to_argv)
|
|
22
24
|
|
|
23
|
-
#=> ["cargo", "
|
|
25
|
+
#=> ["cargo", "b", "-r", "--target", "wasm32-wasip2"]
|
|
24
26
|
```
|
|
25
27
|
|
|
26
28
|
`raw_cmd_hash.then(&hash_to_argv)` is equivalent to:
|
|
27
29
|
|
|
28
30
|
```ruby
|
|
29
|
-
{ cargo: nil,
|
|
31
|
+
{ cargo: nil, b: nil, r: true, target: "wasm32-wasip2" }
|
|
30
32
|
.then(&Argvise.new_proc)
|
|
31
33
|
.with_bsd_style(false) #=> GNU style
|
|
32
34
|
.with_kebab_case_flags(true) #=> replace "--cli_flag" with "--cli-flag"
|
|
@@ -63,22 +65,23 @@ gem install argvise
|
|
|
63
65
|
|
|
64
66
|
### Common
|
|
65
67
|
|
|
66
|
-
| Hash Format
|
|
67
|
-
|
|
|
68
|
-
| `{
|
|
69
|
-
| `{ "-
|
|
70
|
-
| `{
|
|
71
|
-
| `{ key:
|
|
72
|
-
| `{ key:
|
|
73
|
-
| `{
|
|
74
|
-
| `{ k:
|
|
75
|
-
| `{ k:
|
|
76
|
-
| `{ k:
|
|
68
|
+
| Hash Format | Result |
|
|
69
|
+
| ----------------------- | ---------------------------- |
|
|
70
|
+
| `{ "-k2": nil }` | `["-k2"]` |
|
|
71
|
+
| `{ "--r_a-w_": nil }` | `["--r_a-w_"]` |
|
|
72
|
+
| `{ key: nil }` | `["key"]` |
|
|
73
|
+
| `{ key: [] }` | `[]` |
|
|
74
|
+
| `{ key: {} }` | `[]` |
|
|
75
|
+
| `{ key: false }` | `[]` |
|
|
76
|
+
| `{ k: true }` | `["-k"]` |
|
|
77
|
+
| `{ k: "value" }` | `["-k", "value"]` |
|
|
78
|
+
| `{ k: ["a", "b"] }` | `["-k", "a", "-k", "b"]` |
|
|
79
|
+
| `{ k: { a: 1, b: 2 } }` | `["-k", "a=1", "-k", "b=2"]` |
|
|
77
80
|
|
|
78
81
|
|
|
79
82
|
### GNU Style
|
|
80
83
|
|
|
81
|
-
| Hash Format | Result
|
|
84
|
+
| Hash Format | Result |
|
|
82
85
|
| ------------------------- | ---------------------------------- |
|
|
83
86
|
| `{ key: true }` | `["--key"]` |
|
|
84
87
|
| `{ key: "value" }` | `["--key", "value"]` |
|
|
@@ -89,22 +92,22 @@ gem install argvise
|
|
|
89
92
|
|
|
90
93
|
#### `with_kebab_case_flags(true)`:
|
|
91
94
|
|
|
92
|
-
| Hash Format | Result
|
|
93
|
-
| ----------------- |
|
|
94
|
-
| `{ key_a: true }` | `["--key-a"]`
|
|
95
|
+
| Hash Format | Result |
|
|
96
|
+
| ----------------- | ------------- |
|
|
97
|
+
| `{ key_a: true }` | `["--key-a"]` |
|
|
95
98
|
|
|
96
99
|
---
|
|
97
100
|
|
|
98
101
|
#### `with_kebab_case_flags(false)`:
|
|
99
102
|
|
|
100
|
-
| Hash Format | Result
|
|
101
|
-
| ----------------- |
|
|
102
|
-
| `{ key_b: true }` | `["--key_b"]`
|
|
103
|
+
| Hash Format | Result |
|
|
104
|
+
| ----------------- | ------------- |
|
|
105
|
+
| `{ key_b: true }` | `["--key_b"]` |
|
|
103
106
|
|
|
104
107
|
|
|
105
108
|
### BSD Style
|
|
106
109
|
|
|
107
|
-
| Hash Format | Result
|
|
110
|
+
| Hash Format | Result |
|
|
108
111
|
| ------------------------- | -------------------------------- |
|
|
109
112
|
| `{ key: true }` | `["-key"]` |
|
|
110
113
|
| `{ key: "value" }` | `["-key", "value"]` |
|
|
@@ -115,17 +118,17 @@ gem install argvise
|
|
|
115
118
|
|
|
116
119
|
#### `with_kebab_case_flags(true)`:
|
|
117
120
|
|
|
118
|
-
| Hash Format | Result
|
|
119
|
-
| ----------------- |
|
|
120
|
-
| `{ key_c: true }` | `["-key-c"]`
|
|
121
|
+
| Hash Format | Result |
|
|
122
|
+
| ----------------- | ------------ |
|
|
123
|
+
| `{ key_c: true }` | `["-key-c"]` |
|
|
121
124
|
|
|
122
125
|
---
|
|
123
126
|
|
|
124
127
|
#### `with_kebab_case_flags(false)`:
|
|
125
128
|
|
|
126
|
-
| Hash Format | Result
|
|
127
|
-
| ----------------- |
|
|
128
|
-
| `{ key_d: true }` | `["-key_d"]`
|
|
129
|
+
| Hash Format | Result |
|
|
130
|
+
| ----------------- | ------------ |
|
|
131
|
+
| `{ key_d: true }` | `["-key_d"]` |
|
|
129
132
|
|
|
130
133
|
|
|
131
134
|
### Notes
|
data/lib/argvise/version.rb
CHANGED
data/lib/core.rb
CHANGED
|
@@ -7,13 +7,13 @@
|
|
|
7
7
|
#
|
|
8
8
|
# == Example
|
|
9
9
|
#
|
|
10
|
-
# { cargo: nil,
|
|
10
|
+
# { cargo: nil, b: nil, r: true, target: "wasm32-wasip2" }
|
|
11
11
|
# .then(&Argvise.new_proc)
|
|
12
12
|
# .with_bsd_style(false)
|
|
13
13
|
# .build
|
|
14
14
|
# .display
|
|
15
15
|
#
|
|
16
|
-
# #=> ["cargo", "
|
|
16
|
+
# #=> ["cargo", "b", "-r", "--target", "wasm32-wasip2"]
|
|
17
17
|
#
|
|
18
18
|
# == Conversion Rules:
|
|
19
19
|
#
|
|
@@ -90,6 +90,19 @@ class Argvise
|
|
|
90
90
|
new(raw_cmd_hash, opts:).build
|
|
91
91
|
end
|
|
92
92
|
|
|
93
|
+
# Returns a Proc that wraps `Argvise.new`, allowing functional-style chaining.
|
|
94
|
+
#
|
|
95
|
+
# Useful for transforming a hash of CLI arguments into a command array.
|
|
96
|
+
#
|
|
97
|
+
# == Example
|
|
98
|
+
#
|
|
99
|
+
# require 'argvise'
|
|
100
|
+
# { ruby: nil, r: "argvise", e: true, "puts Argvise::VERSION": nil }
|
|
101
|
+
# .then(&Argvise.new_proc)
|
|
102
|
+
# .build
|
|
103
|
+
# .then{system *_1}
|
|
104
|
+
#
|
|
105
|
+
# > See also: [self.new]
|
|
93
106
|
def new_proc
|
|
94
107
|
->(raw_cmd_hash) do
|
|
95
108
|
new(raw_cmd_hash)
|
|
@@ -99,10 +112,11 @@ class Argvise
|
|
|
99
112
|
end
|
|
100
113
|
|
|
101
114
|
# == Example
|
|
115
|
+
#
|
|
102
116
|
# require 'argvise'
|
|
103
117
|
# cmd = { ruby: nil, r: "argvise", verbose: true, e: true, "puts Argvise::VERSION": nil }
|
|
104
118
|
# opts = Argvise::DEFAULT_OPTS
|
|
105
|
-
# Argvise.new(cmd, opts:)
|
|
119
|
+
# Argvise.new(cmd, opts:).build.then{system *_1}
|
|
106
120
|
#
|
|
107
121
|
# == opts
|
|
108
122
|
# [Hash]: { bsd_style: Boolean, kebab_case_flags: Boolean }
|
|
@@ -114,11 +128,11 @@ class Argvise
|
|
|
114
128
|
# will be automatically converted to hyphens (`-`).
|
|
115
129
|
# - For example, a flag like `--enable_jit` will be transformed into `--enable-jit`.
|
|
116
130
|
#
|
|
117
|
-
#
|
|
118
|
-
#
|
|
119
|
-
#
|
|
120
|
-
#
|
|
121
|
-
#
|
|
131
|
+
# When the value of a flag key is `nil`, the `kebab_case_flags` option has no effect
|
|
132
|
+
# — i.e., the key will not be transformed.
|
|
133
|
+
#
|
|
134
|
+
# For example, the input `{"a_b-c": nil}` will result in `["a_b-c"]`,
|
|
135
|
+
# and **not** be automatically transformed into `["a-b-c"]`.
|
|
122
136
|
#
|
|
123
137
|
def initialize(
|
|
124
138
|
raw_cmd_hash,
|