menu_commander 0.1.1 → 0.1.2
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/README.md +33 -3
- data/lib/menu_commander/menu.rb +32 -14
- data/lib/menu_commander/version.rb +1 -1
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 0a654387581a9294b1f966462348cfa72bdca3e3686f362927a5895c8e0e85ce
|
4
|
+
data.tar.gz: de697ea0192672f4dc5e55e1d82083c369e4bebd6a610197f6501d197392c69f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a66bedf0ce90c8d161b4d296c76fa91ac0a9bb614921381fcd3607f7fe568d29806a5ffe66b4cb2ca60e38e78b83bba7d00eaa0b9505c3d02c9f7e0974328acd
|
7
|
+
data.tar.gz: 9bf17c66d38b66a11b2e01c758c9c8d21e134cb2d34bd5a7bc10eb8b4c70a665eb5eb374adc30587f1f2ff1217d38ff8ed956625ce22a12c12637484e80b2e71
|
data/README.md
CHANGED
@@ -14,8 +14,9 @@ Easily create menus for any command line tool using simple YAML configuration.
|
|
14
14
|
Installation
|
15
15
|
--------------------------------------------------
|
16
16
|
|
17
|
-
|
18
|
-
|
17
|
+
```shell
|
18
|
+
$ gem install menu_commander
|
19
|
+
```
|
19
20
|
|
20
21
|
|
21
22
|
Usage
|
@@ -42,7 +43,16 @@ args:
|
|
42
43
|
- Lloyd
|
43
44
|
```
|
44
45
|
|
45
|
-
|
46
|
+
Then, start the menu by running:
|
47
|
+
|
48
|
+
```shell
|
49
|
+
# Start the menu with ./menu.yml
|
50
|
+
$ menu
|
51
|
+
|
52
|
+
# Start the menu with ./some-other-file.yml
|
53
|
+
$ menu some-other-file
|
54
|
+
```
|
55
|
+
|
46
56
|
|
47
57
|

|
48
58
|
|
@@ -84,6 +94,26 @@ args:
|
|
84
94
|
- production
|
85
95
|
```
|
86
96
|
|
97
|
+
In case the argument array contains only one array element for a given
|
98
|
+
variable, it will be automatically used without prompting the user.
|
99
|
+
|
100
|
+
This is useful when you need to define variables that repeat multiple times
|
101
|
+
in your menu.
|
102
|
+
|
103
|
+
```yaml
|
104
|
+
# examples/args-static.yml
|
105
|
+
|
106
|
+
menu:
|
107
|
+
"Show Files": ssh %{server} ls
|
108
|
+
"Reboot": ssh %{server} reboot
|
109
|
+
|
110
|
+
# Using an array with exactly one argument will NOT prompt the user for input
|
111
|
+
# and instead, use the only possible value.
|
112
|
+
args:
|
113
|
+
server:
|
114
|
+
- localhost
|
115
|
+
```
|
116
|
+
|
87
117
|
Using `key: value` pairs in the `args` menu will create a sub-menu with
|
88
118
|
labels that are different from their substituted value:
|
89
119
|
|
data/lib/menu_commander/menu.rb
CHANGED
@@ -10,25 +10,28 @@ module MenuCommander
|
|
10
10
|
@config = config
|
11
11
|
end
|
12
12
|
|
13
|
-
def call(menu
|
13
|
+
def call(menu=nil)
|
14
14
|
menu ||= config['menu']
|
15
15
|
response = select menu
|
16
|
-
response = response
|
16
|
+
response = combine_commands response if response.is_a? Array
|
17
17
|
|
18
|
-
|
19
|
-
|
20
|
-
placeholders(response).each do |key|
|
21
|
-
params[key.to_sym] = get_user_response key
|
22
|
-
end
|
18
|
+
response.is_a?(String) ? evaluate(response) : call(response)
|
19
|
+
end
|
23
20
|
|
24
|
-
|
25
|
-
else
|
26
|
-
call response
|
21
|
+
private
|
27
22
|
|
28
|
-
|
23
|
+
def combine_commands(command_array)
|
24
|
+
command_array.map { |cmd| "(#{cmd})" }.join ' && '
|
29
25
|
end
|
30
26
|
|
31
|
-
|
27
|
+
def evaluate(response)
|
28
|
+
params = {}
|
29
|
+
placeholders(response).each do |key|
|
30
|
+
params[key.to_sym] = get_user_response key
|
31
|
+
end
|
32
|
+
|
33
|
+
response % params
|
34
|
+
end
|
32
35
|
|
33
36
|
def placeholders(template)
|
34
37
|
template.scan(/%{([^}]+)}/).flatten.uniq
|
@@ -40,7 +43,22 @@ module MenuCommander
|
|
40
43
|
|
41
44
|
def get_user_response(key)
|
42
45
|
opts = get_opts key
|
43
|
-
|
46
|
+
opts_type = get_opts_type opts
|
47
|
+
|
48
|
+
case opts_type
|
49
|
+
when :free_text
|
50
|
+
ask(key)
|
51
|
+
when :static
|
52
|
+
opts.first
|
53
|
+
when :menu
|
54
|
+
select(opts, key)
|
55
|
+
end
|
56
|
+
end
|
57
|
+
|
58
|
+
def get_opts_type(opts)
|
59
|
+
return :free_text if !opts
|
60
|
+
return :static if opts.is_a? Array and opts.size == 1
|
61
|
+
:menu
|
44
62
|
end
|
45
63
|
|
46
64
|
def get_opts(key)
|
@@ -62,7 +80,7 @@ module MenuCommander
|
|
62
80
|
|
63
81
|
end
|
64
82
|
|
65
|
-
def select(options, title
|
83
|
+
def select(options, title=nil)
|
66
84
|
title = title ? "> #{title}:" : ">"
|
67
85
|
prompt.select title, options, symbols: { marker: '>' }, per_page: 10, filter: true
|
68
86
|
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: menu_commander
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Danny Ben Shitrit
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2019-
|
11
|
+
date: 2019-10-16 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: mister_bin
|
@@ -86,7 +86,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
86
86
|
- !ruby/object:Gem::Version
|
87
87
|
version: '0'
|
88
88
|
requirements: []
|
89
|
-
rubygems_version: 3.0.
|
89
|
+
rubygems_version: 3.0.4
|
90
90
|
signing_key:
|
91
91
|
specification_version: 4
|
92
92
|
summary: Create menus for any CLI tool
|