argvise 0.0.0 → 0.0.1
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 +119 -0
- data/lib/{argvise.rb → core.rb} +5 -1
- data/rbi/lib/argvise.rbi +12 -0
- metadata +4 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: e3de7b6cddf4e360892acc8de90364c77af210c9f66f171e496d5f1cc5b21ab0
|
4
|
+
data.tar.gz: 950cadc2c4ed07b55b828d1d20e361b529f5516cb6a47693dab887bb94c3cba0
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 70703568c2b83a629b81292bcfc933252fb47ec9904c60e3d2d3aa1fad0de5035684d6b3da5ae952d5df76f31a6d1f29b022c60431fcf2915920237cce314483
|
7
|
+
data.tar.gz: 01e6b640fd724a74778ddbc211ad86d8d52bd39ce1c92d4ac5afdbc3ea4558a756eb2bc13a74b4ea5380f247f11d3cead6e5086809b81d40df3fbfaed77e9bd9
|
data/docs/Readme.md
ADDED
@@ -0,0 +1,119 @@
|
|
1
|
+
# Argvise
|
2
|
+
|
3
|
+
[](https://rubygems.org/gems/argvise)
|
4
|
+
|
5
|
+
A Ruby gem for converting hash structures into command-line argument arrays.
|
6
|
+
|
7
|
+
> **Note:** This is *not* a command-line parser — quite the opposite. Argvise helps you **build** CLI commands programmatically.
|
8
|
+
|
9
|
+
## Installation
|
10
|
+
|
11
|
+
Add this line to your application's Gemfile:
|
12
|
+
|
13
|
+
```ruby
|
14
|
+
gem 'argvise'
|
15
|
+
```
|
16
|
+
|
17
|
+
And then execute:
|
18
|
+
|
19
|
+
```bash
|
20
|
+
bundler install
|
21
|
+
```
|
22
|
+
|
23
|
+
Or install it directly:
|
24
|
+
|
25
|
+
```bash
|
26
|
+
gem install argvise
|
27
|
+
```
|
28
|
+
|
29
|
+
## Usage
|
30
|
+
|
31
|
+
### Basic Conversion
|
32
|
+
|
33
|
+
```ruby
|
34
|
+
require 'argvise'
|
35
|
+
|
36
|
+
options = {
|
37
|
+
docker: nil, #=> docker
|
38
|
+
build: nil,
|
39
|
+
push: true, #=> --push
|
40
|
+
tag: ["ghcr.io/[user]/repo:latest", "ghcr.io/[user]/repo:v0.0.1"], #=> --tag ghcr... --tag ghcr..0.0.1
|
41
|
+
platform: "wasi/wasm", #=> --platform wasi/wasm
|
42
|
+
label: {
|
43
|
+
maintainer: "user",
|
44
|
+
description: "A Docker build example"
|
45
|
+
}, # => --label maintainer=user --label description=A..example
|
46
|
+
file: "wasi.dockerfile",
|
47
|
+
path: nil,
|
48
|
+
}
|
49
|
+
|
50
|
+
Argvise.build(options)
|
51
|
+
# => [
|
52
|
+
# "docker", "build", "--push",
|
53
|
+
# "--tag", "ghcr.io/[user]/repo:latest", "--tag", "ghcr.io/[user]/repo:v0.0.1",
|
54
|
+
# "--platform", "wasi/wasm",
|
55
|
+
# "--label", "maintainer=user", "--label", "description=A Docker build example",
|
56
|
+
# "--file", "wasi.dockerfile", "path"
|
57
|
+
# ]
|
58
|
+
```
|
59
|
+
|
60
|
+
### Lambda Shortcut
|
61
|
+
|
62
|
+
```ruby
|
63
|
+
{ v: true, dir: '/path/to/dir' }.then(&hash_to_args)
|
64
|
+
# => ["-v", "--dir", "/path/to/dir"]
|
65
|
+
```
|
66
|
+
|
67
|
+
## Supported Data Structures
|
68
|
+
|
69
|
+
### 1. Simple Flags
|
70
|
+
|
71
|
+
```ruby
|
72
|
+
{ verbose: true }.then(&hash_to_args) # => ["--verbose"]
|
73
|
+
```
|
74
|
+
|
75
|
+
### 2. Boolean Values
|
76
|
+
|
77
|
+
```ruby
|
78
|
+
{ silent: false }.then(&hash_to_args) # => []
|
79
|
+
```
|
80
|
+
|
81
|
+
### 3. Array Values
|
82
|
+
|
83
|
+
```ruby
|
84
|
+
{ tag: %w[a b] }.then(&hash_to_args)
|
85
|
+
# => ["--tag", "a", "--tag", "b"]
|
86
|
+
```
|
87
|
+
|
88
|
+
### 4. Hash Values
|
89
|
+
|
90
|
+
```ruby
|
91
|
+
{ label: { env: 'test', k2: 'v2' } }.then(&hash_to_args)
|
92
|
+
# => ["--label", "env=test", "--label", "k2=v2"]
|
93
|
+
```
|
94
|
+
|
95
|
+
## API Documentation
|
96
|
+
|
97
|
+
### `Argvise.build(options)`
|
98
|
+
|
99
|
+
Main method to convert hash to command-line arguments array
|
100
|
+
|
101
|
+
**Parameters:**
|
102
|
+
|
103
|
+
- `options` (Hash) - The hash to be converted
|
104
|
+
|
105
|
+
**Returns:**
|
106
|
+
|
107
|
+
- Array<String> generated command-line arguments
|
108
|
+
|
109
|
+
### Conversion Rules
|
110
|
+
|
111
|
+
| Hash Format | Result Example |
|
112
|
+
| ------------------------- | ---------------------------------- |
|
113
|
+
| `{ key: nil }` | `["key"]` |
|
114
|
+
| `{ key: false }` | `[]` |
|
115
|
+
| `{ key: true }` | `["--key"]` |
|
116
|
+
| `{ k: true }` | `["-k"]` |
|
117
|
+
| `{ key: "value" }` | `["--key", "value"]` |
|
118
|
+
| `{ key: ["a", "b"] }` | `["--key", "a", "--key", "b"]` |
|
119
|
+
| `{ key: { a: 1, b: 2 } }` | `["--key", "a=1", "--key", "b=2"]` |
|
data/lib/{argvise.rb → core.rb}
RENAMED
@@ -18,6 +18,8 @@ class Argvise
|
|
18
18
|
#
|
19
19
|
# @param options [Hash] The hash to be converted
|
20
20
|
# @return [Array<String>] The generated array of command-line arguments
|
21
|
+
#
|
22
|
+
# sig { params(options: Hash).returns(T::Array[String]) }
|
21
23
|
def self.build(options)
|
22
24
|
new.build(options)
|
23
25
|
end
|
@@ -92,9 +94,11 @@ class Argvise
|
|
92
94
|
end
|
93
95
|
|
94
96
|
# A convenient lambda method: converts a hash into command-line arguments
|
95
|
-
#
|
97
|
+
#
|
96
98
|
# Example:
|
97
99
|
# { v: true, path: '/path/to/dir' }.then(&hash_to_args) # => ["-v", "--path", "/path/to/dir"]
|
100
|
+
#
|
101
|
+
# sig { returns(T.proc.params(options: Hash).returns(T::Array[String])) }
|
98
102
|
def hash_to_args
|
99
103
|
->(options) do
|
100
104
|
Argvise.build(options)
|
data/rbi/lib/argvise.rbi
ADDED
@@ -0,0 +1,12 @@
|
|
1
|
+
# typed: true
|
2
|
+
# frozen_string_literal: true
|
3
|
+
|
4
|
+
class Argvise
|
5
|
+
class << self
|
6
|
+
sig { params(options: Hash).returns(T::Array[String]) }
|
7
|
+
def build(options); end
|
8
|
+
end
|
9
|
+
end
|
10
|
+
|
11
|
+
sig { returns(T.proc.params(options: Hash).returns(T::Array[String])) }
|
12
|
+
def hash_to_args; 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.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- 2moe
|
@@ -18,7 +18,9 @@ extensions: []
|
|
18
18
|
extra_rdoc_files: []
|
19
19
|
files:
|
20
20
|
- License
|
21
|
-
-
|
21
|
+
- docs/Readme.md
|
22
|
+
- lib/core.rb
|
23
|
+
- rbi/lib/argvise.rbi
|
22
24
|
homepage: https://github.com/2moe/argvise-gem
|
23
25
|
licenses:
|
24
26
|
- Apache-2.0
|