argvise 0.0.4 → 0.0.6

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: d63847d3264553ea75e063063330aff39cb7638bb22d4a227664dfef0f55203b
4
- data.tar.gz: 44335dc0284501d472b81c9427b939000ade17971d0657727b81cc97a4ad631d
3
+ metadata.gz: e02579f4619b47f97e46fe3052e577680cd88ba737f742fe581fc55ef7a54527
4
+ data.tar.gz: '08e79eab0d15b6ec23367d39d23e60dbbc0c969b32e632d6aabb54727136d0c1'
5
5
  SHA512:
6
- metadata.gz: 331dac661ca76f65e605c027be9217b213a97340530c4d4ebe2871979197f37fef9bb6f0ccfe92034faeeb1b879df1db2a180e932dfb992e6b0ae0b4720a690a
7
- data.tar.gz: c00671dfccfba16990b7aff2db61612cbde3ca3b478a6e4b0369181ad6a58aabff3fa28257174bb701fa028b5e6267d227c13b78b85dfc043e8b81309d40de03
6
+ metadata.gz: 87b6122a07799b34702cdc391d8e9c5219ae93c1380f948d0c7359ec71c94e1256274ee03dfd24becd2b0c91f1f2c6992d3a4c8418333dd0a72d8545099a2cc9
7
+ data.tar.gz: de14f0f04cace2b164919228c0126692682acfaab406cb710b27828f1db1731f9a59281609cd5c09aab4344e78aa9a11f4f55e2148c0022e404bbd636bf36ccc
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
- .then(&hash_to_argv)
49
+ .to_argv
47
50
  .display
48
51
 
49
52
  puts_division_line
data/docs/Readme.md CHANGED
@@ -2,6 +2,8 @@
2
2
 
3
3
  [![Gem Version](https://badge.fury.io/rb/argvise.svg?icon=si%3Arubygems)](https://rubygems.org/gems/argvise)
4
4
 
5
+ <!-- [![RubyDoc](https://img.shields.io/badge/-y?label=rubydoc&color=orange)](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,21 @@ system "gem install argvise"
17
19
  # RUBY
18
20
  require 'argvise'
19
21
 
20
- { cargo: nil, build: nil, v: true, target: "wasm32-wasip2" }
21
- .then(&hash_to_argv)
22
+ raw_cmd_hash = {
23
+ cargo: nil, b: nil, r: true, target: "wasm32-wasip2"
24
+ }
25
+
26
+ raw_cmd_hash
27
+ .to_argv
28
+ # .to_argv({bsd_style: false, kebab_case_flags: true})
22
29
 
23
- #=> ["cargo", "build", "-v", "--target", "wasm32-wasip2"]
30
+ #=> ["cargo", "b", "-r", "--target", "wasm32-wasip2"]
24
31
  ```
25
32
 
26
- `raw_cmd_hash.then(&hash_to_argv)` is equivalent to:
33
+ `raw_cmd_hash.to_argv` is equivalent to:
27
34
 
28
35
  ```ruby
29
- { cargo: nil, build: nil, v: true, target: "wasm32-wasip2" }
36
+ raw_cmd_hash
30
37
  .then(&Argvise.new_proc)
31
38
  .with_bsd_style(false) #=> GNU style
32
39
  .with_kebab_case_flags(true) #=> replace "--cli_flag" with "--cli-flag"
@@ -35,6 +42,8 @@ require 'argvise'
35
42
 
36
43
  ## Installation
37
44
 
45
+ ### Ruby MRI
46
+
38
47
  Add this line to your application's Gemfile:
39
48
 
40
49
  ```ruby
@@ -59,26 +68,31 @@ Or install it directly:
59
68
  gem install argvise
60
69
  ```
61
70
 
71
+ ### mruby
72
+
73
+ [More details](../mruby/Readme.md)
74
+
62
75
  ## Conversion Rules
63
76
 
64
77
  ### Common
65
78
 
66
- | Hash Format | Result Example |
67
- | ------------------------ | ---------------------------- |
68
- | `{ key: nil }` | `["key"]` |
69
- | `{ "-k2": nil }` | `["-k2"]` |
70
- | `{ "--r_a-nd_om": nil }` | `["--r_a-nd_om"]` |
71
- | `{ key: false }` | `[]` |
72
- | `{ key: [] }` | `[]` |
73
- | `{ k: true }` | `["-k"]` |
74
- | `{ k: "value" }` | `["-k", "value"]` |
75
- | `{ k: ["a", "b"] }` | `["-k", "a", "-k", "b"]` |
76
- | `{ k: { a: 1, b: 2 } }` | `["-k", "a=1", "-k", "b=2"]` |
79
+ | Hash Format | Result |
80
+ | ----------------------- | ---------------------------- |
81
+ | `{ "-k2": nil }` | `["-k2"]` |
82
+ | `{ "--r_a-w_": nil }` | `["--r_a-w_"]` |
83
+ | `{ key: nil }` | `["key"]` |
84
+ | `{ key: [] }` | `[]` |
85
+ | `{ key: {} }` | `[]` |
86
+ | `{ key: false }` | `[]` |
87
+ | `{ k: true }` | `["-k"]` |
88
+ | `{ k: "value" }` | `["-k", "value"]` |
89
+ | `{ k: ["a", "b"] }` | `["-k", "a", "-k", "b"]` |
90
+ | `{ k: { a: 1, b: 2 } }` | `["-k", "a=1", "-k", "b=2"]` |
77
91
 
78
92
 
79
93
  ### GNU Style
80
94
 
81
- | Hash Format | Result Example |
95
+ | Hash Format | Result |
82
96
  | ------------------------- | ---------------------------------- |
83
97
  | `{ key: true }` | `["--key"]` |
84
98
  | `{ key: "value" }` | `["--key", "value"]` |
@@ -89,22 +103,22 @@ gem install argvise
89
103
 
90
104
  #### `with_kebab_case_flags(true)`:
91
105
 
92
- | Hash Format | Result Example |
93
- | ----------------- | -------------- |
94
- | `{ key_a: true }` | `["--key-a"]` |
106
+ | Hash Format | Result |
107
+ | ----------------- | ------------- |
108
+ | `{ key_a: true }` | `["--key-a"]` |
95
109
 
96
110
  ---
97
111
 
98
112
  #### `with_kebab_case_flags(false)`:
99
113
 
100
- | Hash Format | Result Example |
101
- | ----------------- | -------------- |
102
- | `{ key_b: true }` | `["--key_b"]` |
114
+ | Hash Format | Result |
115
+ | ----------------- | ------------- |
116
+ | `{ key_b: true }` | `["--key_b"]` |
103
117
 
104
118
 
105
119
  ### BSD Style
106
120
 
107
- | Hash Format | Result Example |
121
+ | Hash Format | Result |
108
122
  | ------------------------- | -------------------------------- |
109
123
  | `{ key: true }` | `["-key"]` |
110
124
  | `{ key: "value" }` | `["-key", "value"]` |
@@ -115,17 +129,17 @@ gem install argvise
115
129
 
116
130
  #### `with_kebab_case_flags(true)`:
117
131
 
118
- | Hash Format | Result Example |
119
- | ----------------- | -------------- |
120
- | `{ key_c: true }` | `["-key-c"]` |
132
+ | Hash Format | Result |
133
+ | ----------------- | ------------ |
134
+ | `{ key_c: true }` | `["-key-c"]` |
121
135
 
122
136
  ---
123
137
 
124
138
  #### `with_kebab_case_flags(false)`:
125
139
 
126
- | Hash Format | Result Example |
127
- | ----------------- | -------------- |
128
- | `{ key_d: true }` | `["-key_d"]` |
140
+ | Hash Format | Result |
141
+ | ----------------- | ------------ |
142
+ | `{ key_d: true }` | `["-key_d"]` |
129
143
 
130
144
 
131
145
  ### Notes
@@ -170,7 +184,7 @@ Argvise.build(raw_cmd_hash)
170
184
  ### Lambda Shortcut
171
185
 
172
186
  ```ruby
173
- { v: true, dir: '/path/to/dir' }.then(&hash_to_argv)
187
+ { v: true, dir: '/path/to/dir' }.to_argv
174
188
  # => ["-v", "--dir", "/path/to/dir"]
175
189
  ```
176
190
 
@@ -211,7 +225,7 @@ raw_cmd
211
225
  p '----------------'
212
226
  p 'GNU-style + kebab-case-flags=true'
213
227
  raw_cmd
214
- .then(&hash_to_argv)
228
+ .to_argv
215
229
  .display
216
230
 
217
231
  #=> ["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"]
@@ -284,3 +298,15 @@ raw_cmd
284
298
 
285
299
  - `{ cargo: nil, b: nil}` => `["cargo", "b"]`
286
300
  - `{ "-fv": nil}` => `["-fv"]`
301
+
302
+
303
+ ## Changelog
304
+
305
+ ### v0.0.6 (2025-11-05)
306
+
307
+ Breaking Changes:
308
+
309
+ - `.hash_to_argv` => `Hash.to_argv(opts)`
310
+ - i.e.,
311
+ - old: `{a: true}.then(&hash_to_argv)`
312
+ - new: `{a: true}.to_argv`
@@ -2,5 +2,5 @@
2
2
  # frozen_string_literal: true
3
3
 
4
4
  class Argvise
5
- VERSION = '0.0.4'
5
+ VERSION = '0.0.6'
6
6
  end
data/lib/core.rb CHANGED
@@ -7,13 +7,13 @@
7
7
  #
8
8
  # == Example
9
9
  #
10
- # { cargo: nil, build: nil, v: true, target: "wasm32-wasip2" }
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", "build", "-v", "--target", "wasm32-wasip2"]
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
- # > When the value of a flag key is `nil`, the `kebab_case_flags` option has
118
- # > no effect — i.e., the key will not be transformed.
119
- # >
120
- # > For example, the input `{"a_b-c": nil}` will result in `["a_b-c"]`,
121
- # > and **not** be automatically transformed into `["a-b-c"]`.
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,
@@ -239,23 +253,30 @@ class Argvise
239
253
  end
240
254
  end
241
255
 
242
- # A convenient lambda method: converts a hash into command-line arguments
243
- #
244
- # == Example:
245
- # { v: true, path: '/path/to/dir' }.then(&hash_to_argv)
246
- # #=> ["-v", "--path", "/path/to/dir"]
247
- #
248
- # == raw_cmd_hash.then(&hash_to_argv) is equivalent to:
249
- #
250
- # raw_cmd_hash
251
- # .then(&Argvise.new_proc)
252
- # .with_bsd_style(false)
253
- # .with_kebab_case_flags(true)
254
- # .build
255
- #
256
- # sig { returns(T.proc.params(raw_cmd_hash: Hash).returns(T::Array[String])) }
257
- def hash_to_argv
258
- ->(raw_cmd_hash) do
259
- Argvise.build(raw_cmd_hash)
256
+ class ::Hash # rubocop:disable Style/Documentation
257
+ # A convenient lambda method: 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)
260
281
  end
261
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(self) }
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(self) }
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
- sig { returns(T.proc.params(raw_cmd_hash: T::Hash[T.any(Symbol, String), T.untyped]).returns(T::Array[String])) }
35
- def hash_to_argv; end
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
4
+ version: 0.0.6
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: Turns a hash into CLI arguments
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