menu_commander 0.2.2 → 0.2.3

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 2f80fb34ce5543c0fa380df41394bac243d8d136e120f362f0216eac6b0eff75
4
- data.tar.gz: ff01a61baa3ab61a5c8e082eea7bef4e2e4270a5636ec298b0e4324662fe0fb3
3
+ metadata.gz: 23e8aac2db7da03b17fe9b14fb148c40465b30720e89a0b21260ac0a27089fdf
4
+ data.tar.gz: 548033b637bf604419d6c975b191082d636fe3541c3aaf6e0a11ab6e49342cf8
5
5
  SHA512:
6
- metadata.gz: bd6526bda9eea21153f3c3fa1dbf0a32878cdee6959b032ad60549b0e8e289b6ed63a50b7e35fb5f74656ae8305a0e5349e7623c81a9feaad73dfea250984ef9
7
- data.tar.gz: 6048a220340c27657b03f7bfc742543345b2f675b4f3bc7c431a2f354bf30592da7025b683e7a6d27f3bd279bccdbcc65261ef3b1ebfdc4e8d93fda02a7f2354
6
+ metadata.gz: 25b10ab2564ff96d6353ac1100cbedd223e444c83796fd1ed9991ba8dcf10aedd0a984f40e0326b4f94e1d4e9df2d0483145cd18d4f0de9098eba2881ddc324d
7
+ data.tar.gz: 9e995b8afa4b0b4aa610b90addd94639f453cf6880f940fa77f6147d9b5a0b44c924125cc4a81240731ef20f153354b24ec058014a7f21ce475e8ac55165e305
data/README.md CHANGED
@@ -272,6 +272,7 @@ You can tweak several aspects of the menu by adding an `options` section
272
272
  in your YAML file.
273
273
 
274
274
  ```yaml
275
+ # Optional menu configuration
275
276
  options:
276
277
  # Show header text
277
278
  header: Hello
@@ -304,12 +305,15 @@ options:
304
305
  # Show the command after execution
305
306
  echo: true
306
307
 
307
- # Marker to use when echoing the command
308
- echo_marker: "==>"
308
+ # Marker to use when echoing the command and it was successful
309
+ echo_marker_success: "==>"
310
+
311
+ # Marker to use when echoing the command and it failed
312
+ echo_marker_error: "ERROR ==>"
309
313
 
310
314
  ```
311
315
 
312
- > See: [examples/optons.yml](examples/options.yml)
316
+ > See: [examples/options.yml](examples/options.yml)
313
317
 
314
318
 
315
319
 
data/bin/menu CHANGED
@@ -8,8 +8,10 @@ router = MenuCommander::CLI.router
8
8
  begin
9
9
  exit router.run ARGV
10
10
 
11
- rescue MenuCommander::Interrupt => e
12
- say! "\n#{e.message}"
11
+ rescue MenuCommander::Interrupt, Interrupt => e
12
+ message = e.message
13
+ message = 'Interrupted... Goodbye' if message.empty?
14
+ say! "\n#{message}"
13
15
  exit 0
14
16
 
15
17
  rescue MenuCommander::Exit => e
@@ -23,20 +23,23 @@ module MenuCommander
23
23
  def run
24
24
  verify_sanity
25
25
  say "#{menu.options.header}\n" if menu.options.header
26
+ success = true
26
27
 
27
28
  if args['--loop']
28
29
  run_looped_menu
29
30
  else
30
- run_menu
31
+ success = run_menu
31
32
  end
33
+
34
+ success ? 0 : 1
32
35
  end
33
36
 
37
+ private
38
+
34
39
  def menu
35
40
  @menu ||= Menu.new menu_file
36
41
  end
37
42
 
38
- private
39
-
40
43
  def verify_sanity
41
44
  raise Exit, VERSION if args['--version']
42
45
  raise MenuNotFound.new(paths: menu_paths, config: config) unless menu_file
@@ -59,9 +62,22 @@ module MenuCommander
59
62
  say "$ !txtpur!#{command}".strip if args['--confirm'] or args['--dry']
60
63
 
61
64
  execute = prompt.yes?("Execute?") if args['--confirm']
62
- system command if execute
65
+ success = execute ? system(command) : false
66
+
67
+ echo_footer success, command if menu.options.echo
68
+ success
69
+ end
70
+
71
+ def echo_footer(success, command)
72
+ if success
73
+ marker = menu.options.echo_marker_success
74
+ color = :txtblu
75
+ else
76
+ marker = menu.options.echo_marker_error
77
+ color = :txtred
78
+ end
63
79
 
64
- say "!txtblu!#{menu.options.echo_marker} #{command}".strip if menu.options.echo
80
+ say "!#{color}!#{marker} #{command}".strip
65
81
  end
66
82
 
67
83
  def menu_file
@@ -12,7 +12,8 @@ module MenuCommander
12
12
  @default_options ||= {
13
13
  auto_select: true,
14
14
  echo: false,
15
- echo_marker: '✓',
15
+ echo_marker_success: '✓',
16
+ echo_marker_error: '✗',
16
17
  filter: 'auto',
17
18
  header: false,
18
19
  page_size: 10,
@@ -1,3 +1,3 @@
1
1
  module MenuCommander
2
- VERSION = "0.2.2"
2
+ VERSION = "0.2.3"
3
3
  end
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.2.2
4
+ version: 0.2.3
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-10-21 00:00:00.000000000 Z
11
+ date: 2019-10-22 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: mister_bin