menu_commander 0.1.4 → 0.1.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: 74444d9eb64f53f5fbdc75a27ac41014acf0604136d72a5f0966200ba018751c
4
- data.tar.gz: 21f972e2af7b56540837fcb07efb58cbe062e9779a872e45861691a4daee853e
3
+ metadata.gz: 75da68a2ccd79c2b07b8e61c047dd1047234cb3665c71450cc0bd09402c08cff
4
+ data.tar.gz: 44400006ab0b7525e94459032c0f51393aee61f2bccec3185434676441a8aa78
5
5
  SHA512:
6
- metadata.gz: de5b7bda43aa8b918cfdd978acc9b8e5d315365e5430cf2a1a1227fa680a445d327c6843a6da09800e10594d2863099ba9e42f444c401515d3ce05175cc8bcdc
7
- data.tar.gz: 602592a70232ef56c6125ff97f701b2877195e94bc14877e98759933e245dec517826285c4009a4fb01dccafdfc366000de8c81d7cbbf2da6dccb64c55279a5f
6
+ metadata.gz: fea9fd9cf567cc67ce6c0bea3edb78fb5819c2ef83dcdce541f00868aba2a508711bb169bdb58bef496bdb5b15afe99863fec968b7545217c916da3a0f278e6c
7
+ data.tar.gz: a29a5eaf1a29b696bab6d36e17a88b57c07366993b0445750c3e03dc6c700fcdcea934bb376497d8216cd03dceb2d517a2036c2f579fad490124cec68c5dc733
data/README.md CHANGED
@@ -11,6 +11,20 @@ Easily create menus for any command line tool using simple YAML configuration.
11
11
 
12
12
  ---
13
13
 
14
+ * [Installation](#installation)
15
+ * [Usage](#usage)
16
+ * [Menu Configuration Features](#menu-configuration-features)
17
+ * [Minimal menu requirements](#minimal-menu-requirements)
18
+ * [Argument sub-menus](#argument-sub-menus)
19
+ * [Free text input](#free-text-input)
20
+ * [Nested menus](#nested-menus)
21
+ * [Header text](#header-text)
22
+ * [Split menu into several files](#split-menu-into-several-files)
23
+ * [Multi-line commands](#multi-line-commands)
24
+ * [Menu File Location](#menu-file-location)
25
+
26
+ ---
27
+
14
28
  Installation
15
29
  --------------------------------------------------
16
30
 
@@ -71,19 +85,19 @@ The only requirement for a minimal menu is to have a `menu` definition
71
85
  with `key: command` to run.
72
86
 
73
87
  ```yaml
74
- # examples/minimal.yml
75
88
  menu:
76
89
  hello: echo hello
77
90
  whoami: whoami
78
91
  ```
79
92
 
93
+ > See: [examples/minimal.yml](examples/minimal.yml)
94
+
80
95
  ### Argument sub-menus
81
96
 
82
97
  Using `%{variables}` in a command will prompt for an input when executed. The
83
98
  sub-menu for that input is specified in the `args` definition.
84
99
 
85
100
  ```yaml
86
- # examples/args-array.yml
87
101
  menu:
88
102
  server: rails server --env %{environment}
89
103
  test: RAILS_ENV=%{environment} rspec
@@ -94,6 +108,8 @@ args:
94
108
  - production
95
109
  ```
96
110
 
111
+ > See: [examples/args-array.yml](examples/args-array.yml)
112
+
97
113
  In case the argument array contains only one array element for a given
98
114
  variable, it will be automatically used without prompting the user.
99
115
 
@@ -101,24 +117,16 @@ This is useful when you need to define variables that repeat multiple times
101
117
  in your menu.
102
118
 
103
119
  ```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
120
  args:
113
- server:
114
- - localhost
121
+ server: [localhost]
115
122
  ```
116
123
 
124
+ > See: [examples/args-static.yml](examples/args-static.yml)
125
+
117
126
  Using `key: value` pairs in the `args` menu will create a sub-menu with
118
127
  labels that are different from their substituted value:
119
128
 
120
129
  ```yaml
121
- # examples/args-hash.yml
122
130
  menu:
123
131
  server: rails server --env %{environment}
124
132
  test: RAILS_ENV=%{environment} rspec
@@ -129,12 +137,13 @@ args:
129
137
  Production Environment: production
130
138
  ```
131
139
 
140
+ > See: [examples/args-hash.yml](examples/args-hash.yml)
141
+
132
142
  In order to obtain the sub-menu items from a shell command, simply provide
133
143
  the command to run, instead of providing the menu options. The command is
134
144
  expected to provide newline-delimited output.
135
145
 
136
146
  ```yaml
137
- # examples/args-shell.yml
138
147
  menu:
139
148
  show: cat %{file}
140
149
  edit: vi %{file}
@@ -143,25 +152,27 @@ args:
143
152
  file: ls
144
153
  ```
145
154
 
155
+ > See: [examples/args-shell.yml](examples/args-shell.yml)
156
+
146
157
  ### Free text input
147
158
 
148
159
  When using a `%{variable}` that does not have a corresponding definition in
149
160
  the `args` section, you will simply be prompted for a free text input:
150
161
 
151
162
  ```yaml
152
- # examples/args-free-text.yml
153
163
  menu:
154
164
  release:
155
165
  echo %{version} > version.txt &&
156
166
  git tag v%{version}
157
167
  ```
158
168
 
169
+ > See: [examples/args-free-text.yml](examples/args-free-text.yml)
170
+
159
171
  ### Nested menus
160
172
 
161
173
  You can nest as many menu levels as you wish under the menu definition.
162
174
 
163
175
  ```yaml
164
- # examples/nested.yml
165
176
  menu:
166
177
  docker:
167
178
  images: docker images ls
@@ -175,6 +186,64 @@ menu:
175
186
  branch: git branch
176
187
  ```
177
188
 
189
+ > See: [examples/args-nested.yml](examples/args-nested.yml)
190
+
191
+
192
+ ### Header text
193
+
194
+ Use the `header` option to display a sentence or a multi-line paragraph when
195
+ the menu is started. The header string supports [colsole color markers][1]:
196
+
197
+ ```yaml
198
+ header: |-
199
+ Welcome to this !txtgrn!basic menu
200
+ !bldred!Multiline!txtrst! headers are allowed
201
+ ```
202
+
203
+ > See: [examples/header.yml](examples/header.yml)
204
+
205
+
206
+ ### Split menu into several files
207
+
208
+ Each menu configuration file can include any number of additional YAML
209
+ files inside it. This is useful when:
210
+
211
+ - Your menu configuration file becomes too long, and you wish to split it
212
+ to separate logical units.
213
+ - You have multiple menu files, and you want to include common configuration
214
+ in each of them.
215
+
216
+ This is done by using the `extends` option:
217
+
218
+ ```yaml
219
+ # examples/extend.yml
220
+ extends: extend-parent.yml
221
+
222
+ menu:
223
+ hello: echo hello
224
+ hi: echo hi %{name}
225
+
226
+ args:
227
+ name: [Harry, Lloyd]
228
+ server: [example.com]
229
+ ```
230
+
231
+ > See: [examples/extend.yml](examples/extend.yml)
232
+
233
+ The below configuration will be merged into the above menu:
234
+
235
+ ```yaml
236
+ # examples/extend-parent.yml
237
+ menu:
238
+ ping: ping %{server}
239
+
240
+ args:
241
+ server: [localhost, google.com]
242
+ ```
243
+
244
+ > See: [examples/extend-parent.yml](examples/extend-parent.yml)
245
+
246
+
178
247
  ### Multi-line commands
179
248
 
180
249
  Providing an array to a menu, will join the array with '&&' to a single
@@ -182,7 +251,6 @@ command. Alternatively, you can use a simple YAML multi-line string.
182
251
 
183
252
 
184
253
  ```yaml
185
- # examples/multiline.yml
186
254
  menu:
187
255
  deploy:
188
256
  - run tests
@@ -195,6 +263,8 @@ menu:
195
263
  git push
196
264
  ```
197
265
 
266
+ > See: [examples/multiline.yml](examples/multiline.yml)
267
+
198
268
 
199
269
  Menu File Location
200
270
  --------------------------------------------------
@@ -214,3 +284,4 @@ If you wish this setting to be permanent, add it to your `.bashrc` or your
214
284
  preferred initialization script.
215
285
 
216
286
 
287
+ [1]: https://github.com/dannyben/colsole#color-codes
@@ -20,8 +20,8 @@ module MenuCommander
20
20
  attr_reader :last_command
21
21
 
22
22
  def run
23
- raise Exit, VERSION if args['--version']
24
- raise MenuNotFound.new(paths: menu_paths, config: config) unless menu_file
23
+ verify_sanity
24
+ say "#{menu.header}\n" if menu.header
25
25
 
26
26
  if args['--loop']
27
27
  run_looped_menu
@@ -36,6 +36,11 @@ module MenuCommander
36
36
 
37
37
  private
38
38
 
39
+ def verify_sanity
40
+ raise Exit, VERSION if args['--version']
41
+ raise MenuNotFound.new(paths: menu_paths, config: config) unless menu_file
42
+ end
43
+
39
44
  def run_looped_menu
40
45
  loop do
41
46
  run_menu
@@ -19,6 +19,10 @@ module MenuCommander
19
19
  response.is_a?(String) ? evaluate(response) : call(response)
20
20
  end
21
21
 
22
+ def header
23
+ config['header']
24
+ end
25
+
22
26
  private
23
27
 
24
28
  def combine_commands(command_array)
@@ -1,3 +1,3 @@
1
1
  module MenuCommander
2
- VERSION = "0.1.4"
2
+ VERSION = "0.1.5"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: menu_commander
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.4
4
+ version: 0.1.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Danny Ben Shitrit