argvise 0.0.5 → 0.0.7
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/bin/console.rb +4 -1
- data/docs/Readme.md +50 -26
- data/lib/argvise/version.rb +1 -1
- data/lib/core.rb +31 -24
- data/rbi/lib/argvise.rbi +6 -4
- metadata +2 -3
- data/argvise.gemspec +0 -47
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: baf5e36d57cbce4d441556b353f25a40cccb258762496b029ea31931c5f0a9ce
|
|
4
|
+
data.tar.gz: 6727e52bba5ce34e77e5649700c9c404fce0a66d7f7223f5a8f8e9e6abbfd21d
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 97ad4a558c1b08ec2b64607e92761bb9ea1592cbfbb3d96fa9307179ae77e1123d6a2ef28725b36d77a2bd15d11dcf4a00cafe11868fab20adf3d73a926a9b3b
|
|
7
|
+
data.tar.gz: 3de59adb8b956fdb71342fb84064ba9a5a0fcc6030bf5e83a17ba2512223cc4185685057c9e2bd18efa0fefd0e4485d165282fc33efca534b9f8059ceff95417
|
data/bin/console.rb
CHANGED
|
@@ -1,9 +1,12 @@
|
|
|
1
1
|
#!/usr/bin/env ruby
|
|
2
|
+
# typed: ignore
|
|
2
3
|
# frozen_string_literal: true
|
|
3
4
|
|
|
4
5
|
# lib_path = File.expand_path('../lib', __dir__)
|
|
5
6
|
# exec "irb -I #{lib_path} -r argvise"
|
|
6
7
|
|
|
8
|
+
# require "bundler/setup"
|
|
9
|
+
# require "argvise"
|
|
7
10
|
require 'irb'
|
|
8
11
|
require_relative '../lib/argvise'
|
|
9
12
|
|
|
@@ -43,7 +46,7 @@ puts_division_line
|
|
|
43
46
|
|
|
44
47
|
puts 'GNU-style + kebab_case_flags(true)'
|
|
45
48
|
raw_cmd
|
|
46
|
-
.
|
|
49
|
+
.to_argv
|
|
47
50
|
.display
|
|
48
51
|
|
|
49
52
|
puts_division_line
|
data/docs/Readme.md
CHANGED
|
@@ -19,16 +19,21 @@ system "gem install argvise"
|
|
|
19
19
|
# RUBY
|
|
20
20
|
require 'argvise'
|
|
21
21
|
|
|
22
|
-
|
|
23
|
-
|
|
22
|
+
raw_cmd_hash = {
|
|
23
|
+
cargo: (), b: (), r: true, target: "wasm32-wasip2"
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
raw_cmd_hash
|
|
27
|
+
.to_argv
|
|
28
|
+
# .to_argv({bsd_style: false, kebab_case_flags: true})
|
|
24
29
|
|
|
25
30
|
#=> ["cargo", "b", "-r", "--target", "wasm32-wasip2"]
|
|
26
31
|
```
|
|
27
32
|
|
|
28
|
-
`raw_cmd_hash.
|
|
33
|
+
`raw_cmd_hash.to_argv` is equivalent to:
|
|
29
34
|
|
|
30
35
|
```ruby
|
|
31
|
-
|
|
36
|
+
raw_cmd_hash
|
|
32
37
|
.then(&Argvise.new_proc)
|
|
33
38
|
.with_bsd_style(false) #=> GNU style
|
|
34
39
|
.with_kebab_case_flags(true) #=> replace "--cli_flag" with "--cli-flag"
|
|
@@ -37,6 +42,8 @@ require 'argvise'
|
|
|
37
42
|
|
|
38
43
|
## Installation
|
|
39
44
|
|
|
45
|
+
### Ruby MRI
|
|
46
|
+
|
|
40
47
|
Add this line to your application's Gemfile:
|
|
41
48
|
|
|
42
49
|
```ruby
|
|
@@ -61,6 +68,10 @@ Or install it directly:
|
|
|
61
68
|
gem install argvise
|
|
62
69
|
```
|
|
63
70
|
|
|
71
|
+
### mruby
|
|
72
|
+
|
|
73
|
+
[More details](../mruby/Readme.md)
|
|
74
|
+
|
|
64
75
|
## Conversion Rules
|
|
65
76
|
|
|
66
77
|
### Common
|
|
@@ -70,6 +81,7 @@ gem install argvise
|
|
|
70
81
|
| `{ "-k2": nil }` | `["-k2"]` |
|
|
71
82
|
| `{ "--r_a-w_": nil }` | `["--r_a-w_"]` |
|
|
72
83
|
| `{ key: nil }` | `["key"]` |
|
|
84
|
+
| `{ key: () }` | `["key"]` |
|
|
73
85
|
| `{ key: [] }` | `[]` |
|
|
74
86
|
| `{ key: {} }` | `[]` |
|
|
75
87
|
| `{ key: false }` | `[]` |
|
|
@@ -78,7 +90,6 @@ gem install argvise
|
|
|
78
90
|
| `{ k: ["a", "b"] }` | `["-k", "a", "-k", "b"]` |
|
|
79
91
|
| `{ k: { a: 1, b: 2 } }` | `["-k", "a=1", "-k", "b=2"]` |
|
|
80
92
|
|
|
81
|
-
|
|
82
93
|
### GNU Style
|
|
83
94
|
|
|
84
95
|
| Hash Format | Result |
|
|
@@ -90,7 +101,7 @@ gem install argvise
|
|
|
90
101
|
|
|
91
102
|
---
|
|
92
103
|
|
|
93
|
-
#### `with_kebab_case_flags(true)
|
|
104
|
+
#### `with_kebab_case_flags(true)`
|
|
94
105
|
|
|
95
106
|
| Hash Format | Result |
|
|
96
107
|
| ----------------- | ------------- |
|
|
@@ -98,13 +109,12 @@ gem install argvise
|
|
|
98
109
|
|
|
99
110
|
---
|
|
100
111
|
|
|
101
|
-
#### `with_kebab_case_flags(false)
|
|
112
|
+
#### `with_kebab_case_flags(false)`
|
|
102
113
|
|
|
103
114
|
| Hash Format | Result |
|
|
104
115
|
| ----------------- | ------------- |
|
|
105
116
|
| `{ key_b: true }` | `["--key_b"]` |
|
|
106
117
|
|
|
107
|
-
|
|
108
118
|
### BSD Style
|
|
109
119
|
|
|
110
120
|
| Hash Format | Result |
|
|
@@ -116,7 +126,9 @@ gem install argvise
|
|
|
116
126
|
|
|
117
127
|
---
|
|
118
128
|
|
|
119
|
-
|
|
129
|
+
<!-- markdownlint-disable MD024 no-duplicate-heading -->
|
|
130
|
+
|
|
131
|
+
#### `with_kebab_case_flags(true)`
|
|
120
132
|
|
|
121
133
|
| Hash Format | Result |
|
|
122
134
|
| ----------------- | ------------ |
|
|
@@ -124,13 +136,12 @@ gem install argvise
|
|
|
124
136
|
|
|
125
137
|
---
|
|
126
138
|
|
|
127
|
-
#### `with_kebab_case_flags(false)
|
|
139
|
+
#### `with_kebab_case_flags(false)`
|
|
128
140
|
|
|
129
141
|
| Hash Format | Result |
|
|
130
142
|
| ----------------- | ------------ |
|
|
131
143
|
| `{ key_d: true }` | `["-key_d"]` |
|
|
132
144
|
|
|
133
|
-
|
|
134
145
|
### Notes
|
|
135
146
|
|
|
136
147
|
> When the value of a flag key is `nil`, the `kebab_case_flags` option has
|
|
@@ -173,20 +184,21 @@ Argvise.build(raw_cmd_hash)
|
|
|
173
184
|
### Lambda Shortcut
|
|
174
185
|
|
|
175
186
|
```ruby
|
|
176
|
-
{ v: true, dir: '/path/to/dir' }.
|
|
187
|
+
{ v: true, dir: '/path/to/dir' }.to_argv
|
|
177
188
|
# => ["-v", "--dir", "/path/to/dir"]
|
|
178
189
|
```
|
|
179
190
|
|
|
180
191
|
### Configurable builder
|
|
181
192
|
|
|
182
193
|
> Required
|
|
183
|
-
>
|
|
184
|
-
>
|
|
194
|
+
>
|
|
195
|
+
> - argvise: >= v0.0.6
|
|
196
|
+
> - ruby: >= v3.1.0
|
|
185
197
|
|
|
186
198
|
```ruby
|
|
187
199
|
raw_cmd = {
|
|
188
|
-
compiler:
|
|
189
|
-
build:
|
|
200
|
+
compiler: (),
|
|
201
|
+
build: (),
|
|
190
202
|
pack_type: 'tar+zstd',
|
|
191
203
|
push: true,
|
|
192
204
|
v: true,
|
|
@@ -197,7 +209,7 @@ raw_cmd = {
|
|
|
197
209
|
maintainer: 'user',
|
|
198
210
|
description: 'Demo'
|
|
199
211
|
},
|
|
200
|
-
"/path/to/dir":
|
|
212
|
+
"/path/to/dir": ()
|
|
201
213
|
}
|
|
202
214
|
|
|
203
215
|
p '----------------'
|
|
@@ -214,7 +226,7 @@ raw_cmd
|
|
|
214
226
|
p '----------------'
|
|
215
227
|
p 'GNU-style + kebab-case-flags=true'
|
|
216
228
|
raw_cmd
|
|
217
|
-
.
|
|
229
|
+
.to_argv
|
|
218
230
|
.display
|
|
219
231
|
|
|
220
232
|
#=> ["compiler", "build", "--pack-type", "tar+zstd", "--push", "-v", "-f", "p2", "--tag", "v0.0.1", "--tag", "beta", "--platform", "wasi/wasm", "--label", "maintainer=user", "--label", "description=Demo", "/path/to/dir"]
|
|
@@ -237,15 +249,15 @@ raw_cmd
|
|
|
237
249
|
|
|
238
250
|
#### GNU style
|
|
239
251
|
|
|
240
|
-
- `{ verbose: true }` => "--verbose"
|
|
241
|
-
- `{ v: true }` => "-v"
|
|
242
|
-
- `{ v: false }` =>
|
|
252
|
+
- `{ verbose: true }` => `["--verbose"]`
|
|
253
|
+
- `{ v: true }` => `["-v"]`
|
|
254
|
+
- `{ v: false }` => `[]`
|
|
243
255
|
|
|
244
256
|
#### BSD style
|
|
245
257
|
|
|
246
|
-
- `{ verbose: true }` => "-verbose"
|
|
247
|
-
- `{ v: true }` => "-v"
|
|
248
|
-
- `{ v: false }` =>
|
|
258
|
+
- `{ verbose: true }` => `["-verbose"]`
|
|
259
|
+
- `{ v: true }` => `["-v"]`
|
|
260
|
+
- `{ v: false }` => `[]`
|
|
249
261
|
|
|
250
262
|
### String
|
|
251
263
|
|
|
@@ -285,5 +297,17 @@ raw_cmd
|
|
|
285
297
|
|
|
286
298
|
## Nil => Raw
|
|
287
299
|
|
|
288
|
-
- `{ cargo:
|
|
289
|
-
- `{
|
|
300
|
+
- `{ cargo: () }` => `["cargo"]`
|
|
301
|
+
- `{ cargo: nil, b: nil }` => `["cargo", "b"]`
|
|
302
|
+
- `{ "-fv": nil }` => `["-fv"]`
|
|
303
|
+
|
|
304
|
+
## Changelog
|
|
305
|
+
|
|
306
|
+
### v0.0.6 (2025-11-05)
|
|
307
|
+
|
|
308
|
+
Breaking Changes:
|
|
309
|
+
|
|
310
|
+
- `cmd_hash |> hash_to_argv` => `cmd_hash.to_argv(opts)`
|
|
311
|
+
- i.e.,
|
|
312
|
+
- old: `{a: true}.then(&hash_to_argv)`
|
|
313
|
+
- new: `{a: true}.to_argv`
|
data/lib/argvise/version.rb
CHANGED
data/lib/core.rb
CHANGED
|
@@ -19,9 +19,9 @@
|
|
|
19
19
|
#
|
|
20
20
|
# === GNU Style:
|
|
21
21
|
# - Boolean values:
|
|
22
|
-
# - `{ verbose: true }` => "--verbose"
|
|
23
|
-
# - `{ v: true }` => "-v"
|
|
24
|
-
# - `{ v: false }` => no argument generated
|
|
22
|
+
# - `{ verbose: true }` => ["--verbose"]
|
|
23
|
+
# - `{ v: true }` => ["-v"]
|
|
24
|
+
# - `{ v: false }` => [] #no argument generated
|
|
25
25
|
# - String values:
|
|
26
26
|
# - `{ f: "a.txt" }` => ["-f", "a.txt"]
|
|
27
27
|
# - `{ file: "a.txt" }` => ["--file", "a.txt"]
|
|
@@ -34,9 +34,9 @@
|
|
|
34
34
|
#
|
|
35
35
|
# === BSD Style:
|
|
36
36
|
# - Boolean values:
|
|
37
|
-
# - `{ verbose: true }` => "-verbose"
|
|
38
|
-
# - `{ v: true }` => "-v"
|
|
39
|
-
# - `{ v: false }` => no argument generated
|
|
37
|
+
# - `{ verbose: true }` => ["-verbose"]
|
|
38
|
+
# - `{ v: true }` => ["-v"]
|
|
39
|
+
# - `{ v: false }` => [] #no argument generated
|
|
40
40
|
# - String values:
|
|
41
41
|
# - `{ f: "a.txt" }` => ["-f", "a.txt"]
|
|
42
42
|
# - `{ file: "a.txt" }` => ["-file", "a.txt"]
|
|
@@ -253,23 +253,30 @@ class Argvise
|
|
|
253
253
|
end
|
|
254
254
|
end
|
|
255
255
|
|
|
256
|
-
|
|
257
|
-
#
|
|
258
|
-
#
|
|
259
|
-
#
|
|
260
|
-
#
|
|
261
|
-
#
|
|
262
|
-
#
|
|
263
|
-
#
|
|
264
|
-
#
|
|
265
|
-
#
|
|
266
|
-
#
|
|
267
|
-
#
|
|
268
|
-
#
|
|
269
|
-
#
|
|
270
|
-
#
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
256
|
+
class ::Hash # rubocop:disable Style/Documentation
|
|
257
|
+
# Converts a hash into command-line arguments
|
|
258
|
+
#
|
|
259
|
+
# == Example:
|
|
260
|
+
#
|
|
261
|
+
# { v: true, path: '/path/to/dir' }.to_argv
|
|
262
|
+
# #=> ["-v", "--path", "/path/to/dir"]
|
|
263
|
+
#
|
|
264
|
+
# == params:
|
|
265
|
+
#
|
|
266
|
+
# - opts: See also [Argvise::new]
|
|
267
|
+
#
|
|
268
|
+
# == raw_cmd_hash.to_argv is equivalent to:
|
|
269
|
+
#
|
|
270
|
+
# raw_cmd_hash
|
|
271
|
+
# .then(&Argvise.new_proc)
|
|
272
|
+
# .with_bsd_style(false)
|
|
273
|
+
# .with_kebab_case_flags(true)
|
|
274
|
+
# .build
|
|
275
|
+
#
|
|
276
|
+
# ---
|
|
277
|
+
#
|
|
278
|
+
# sig { params(opts: T.nilable(Hash)).returns(T::Array[String]) }
|
|
279
|
+
def to_argv(opts = nil)
|
|
280
|
+
Argvise.build(self, opts: opts)
|
|
274
281
|
end
|
|
275
282
|
end
|
data/rbi/lib/argvise.rbi
CHANGED
|
@@ -21,15 +21,17 @@ class Argvise
|
|
|
21
21
|
end
|
|
22
22
|
def initialize(raw_cmd_hash, opts: nil); end
|
|
23
23
|
|
|
24
|
-
sig { params(value: T::Boolean).returns(
|
|
24
|
+
sig { params(value: T::Boolean).returns(T.self_type) }
|
|
25
25
|
def with_bsd_style(value = true); end # rubocop:disable Style/OptionalBooleanParameter
|
|
26
26
|
|
|
27
|
-
sig { params(value: T::Boolean).returns(
|
|
27
|
+
sig { params(value: T::Boolean).returns(T.self_type) }
|
|
28
28
|
def with_kebab_case_flags(value = true); end # rubocop:disable Style/OptionalBooleanParameter
|
|
29
29
|
|
|
30
30
|
sig { returns(T::Array[String]) }
|
|
31
31
|
def build; end
|
|
32
32
|
end
|
|
33
33
|
|
|
34
|
-
|
|
35
|
-
|
|
34
|
+
class ::Hash
|
|
35
|
+
sig { params(opts: T.nilable(Hash)).returns(T::Array[String]) }
|
|
36
|
+
def to_argv(opts = nil); end
|
|
37
|
+
end
|
metadata
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: argvise
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.0.
|
|
4
|
+
version: 0.0.7
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- 2moe
|
|
@@ -19,7 +19,6 @@ extra_rdoc_files: []
|
|
|
19
19
|
files:
|
|
20
20
|
- ".rubocop.yml"
|
|
21
21
|
- License
|
|
22
|
-
- argvise.gemspec
|
|
23
22
|
- bin/build.rb
|
|
24
23
|
- bin/console.rb
|
|
25
24
|
- docs/Readme.md
|
|
@@ -48,5 +47,5 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
|
48
47
|
requirements: []
|
|
49
48
|
rubygems_version: 3.7.2
|
|
50
49
|
specification_version: 4
|
|
51
|
-
summary:
|
|
50
|
+
summary: Converts a hash into CLI arguments [Array]
|
|
52
51
|
test_files: []
|
data/argvise.gemspec
DELETED
|
@@ -1,47 +0,0 @@
|
|
|
1
|
-
# frozen_string_literal: true
|
|
2
|
-
|
|
3
|
-
require_relative 'lib/argvise/version'
|
|
4
|
-
|
|
5
|
-
Gem::Specification.new do |spec|
|
|
6
|
-
spec.name = 'argvise'
|
|
7
|
-
# spec.version = '0.0.1'
|
|
8
|
-
spec.version = Argvise::VERSION
|
|
9
|
-
spec.authors = ['2moe']
|
|
10
|
-
spec.email = ['m@tmoe.me']
|
|
11
|
-
|
|
12
|
-
spec.summary = 'Turns a hash into CLI arguments'
|
|
13
|
-
spec.description = 'Provides flexible command-line argument generation with support for complex data structures'
|
|
14
|
-
spec.license = 'Apache-2.0'
|
|
15
|
-
# spec.extra_rdoc_files = ['docs/rdoc/Readme.rdoc']
|
|
16
|
-
spec.required_ruby_version = '>= 3.1.0'
|
|
17
|
-
# spec.metadata['allowed_push_host'] = "TODO: Set to your gem server 'https://example.com'"
|
|
18
|
-
|
|
19
|
-
spec.homepage = 'https://github.com/2moe/argvise-gem'
|
|
20
|
-
spec.metadata['homepage_uri'] = spec.homepage
|
|
21
|
-
# spec.metadata['source_code_uri'] = spec.homepage
|
|
22
|
-
# spec.metadata['changelog_uri'] = "TODO: Put your gem's CHANGELOG.md URL here."
|
|
23
|
-
|
|
24
|
-
# Specify which files should be added to the gem when it is released.
|
|
25
|
-
# The `git ls-files -z` loads the files in the RubyGem that have been added into git.
|
|
26
|
-
# gemspec = File.basename(__FILE__)
|
|
27
|
-
spec.files = IO.popen(%w[git ls-files -z], chdir: __dir__, err: IO::NULL) do |ls|
|
|
28
|
-
ls.readlines("\x0", chomp: true).reject do |f|
|
|
29
|
-
# (f == gemspec) ||
|
|
30
|
-
f.start_with?(
|
|
31
|
-
# bin/ test/ Gemfile Rakefile assets docs/Readme-zh-
|
|
32
|
-
*%w[
|
|
33
|
-
spec/ features/ .git .github appveyor
|
|
34
|
-
]
|
|
35
|
-
)
|
|
36
|
-
end
|
|
37
|
-
end
|
|
38
|
-
# spec.bindir = 'exe'
|
|
39
|
-
# spec.executables = spec.files.grep(%r{\Aexe/}) { |f| File.basename(f) }
|
|
40
|
-
spec.require_paths = ['lib']
|
|
41
|
-
|
|
42
|
-
# Uncomment to register a new dependency of your gem
|
|
43
|
-
# spec.add_dependency "example-gem", "~> 1.0"
|
|
44
|
-
|
|
45
|
-
# For more information and examples about making a new gem, check out our
|
|
46
|
-
# guide at: https://bundler.io/guides/creating_gem.html
|
|
47
|
-
end
|