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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: d63847d3264553ea75e063063330aff39cb7638bb22d4a227664dfef0f55203b
4
- data.tar.gz: 44335dc0284501d472b81c9427b939000ade17971d0657727b81cc97a4ad631d
3
+ metadata.gz: cc2e3625fabe3294535d920c085b82f1c2718032de5f3921a7a9f74424c1ca5f
4
+ data.tar.gz: 2005628bc2fc53ea8937a310111b4217289051e3c634d5960287ed9e4db4dca0
5
5
  SHA512:
6
- metadata.gz: 331dac661ca76f65e605c027be9217b213a97340530c4d4ebe2871979197f37fef9bb6f0ccfe92034faeeb1b879df1db2a180e932dfb992e6b0ae0b4720a690a
7
- data.tar.gz: c00671dfccfba16990b7aff2db61612cbde3ca3b478a6e4b0369181ad6a58aabff3fa28257174bb701fa028b5e6267d227c13b78b85dfc043e8b81309d40de03
6
+ metadata.gz: 1f78e1ea42b3d355ec65da36c69bbf31b7dfa7386c7483ed42c625ef15dc826f052e7009f040a47ef0f685a2f4d26de347edfeeba9c53c09cdb7941bc5b6915a
7
+ data.tar.gz: a9c6c99a0590f822f5dda6782a3a12c664008c8eff472c234f004e9b2fb69033e12dba58d8efd6c9bb77ec449cc97dab121cf875e80535f226f0ec29c3aea45c
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,16 @@ system "gem install argvise"
17
19
  # RUBY
18
20
  require 'argvise'
19
21
 
20
- { cargo: nil, build: nil, v: true, target: "wasm32-wasip2" }
22
+ { cargo: nil, b: nil, r: true, target: "wasm32-wasip2" }
21
23
  .then(&hash_to_argv)
22
24
 
23
- #=> ["cargo", "build", "-v", "--target", "wasm32-wasip2"]
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, build: nil, v: true, target: "wasm32-wasip2" }
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 | 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"]` |
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 Example |
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 Example |
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 Example |
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 Example |
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 Example |
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 Example |
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
@@ -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.5'
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,
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.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - 2moe