menu_commander 0.2.6 → 0.2.7
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/bin/menu +8 -13
- data/lib/menu_commander/command.rb +19 -19
- data/lib/menu_commander/exceptions.rb +8 -7
- data/lib/menu_commander/menu.rb +20 -27
- data/lib/menu_commander/menu_options.rb +13 -13
- data/lib/menu_commander/version.rb +2 -2
- data/lib/menu_commander.rb +0 -1
- metadata +26 -20
- data/lib/menu_commander/polyfills/hash.rb +0 -11
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: a48d60fb83fd26d522bc9cc7380d16412f17c965a9434ea3763cfbe9a735e90f
|
4
|
+
data.tar.gz: 7de8761c8ac902d24ca76e9ff2bbbb3f175aeb10cc11ded5f87aedf543610f25
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e7c83688bdb202b27b63ce8442d3ae770fd0d5f5c44d8d74e9018963123b12e05e4011ada408ec57eb4f34eb7dbda0860ec93b491d87f4bcab9c7cbbda7d7e8d
|
7
|
+
data.tar.gz: 550ee1aa662f2358805d59d78495d2a76cb918ef4569e4de334528267efd368276f326b85e4acea60e8b2ee2600f9bdedbe73cbff21a80c2433a9ddf9e268d92
|
data/bin/menu
CHANGED
@@ -7,36 +7,31 @@ router = MenuCommander::CLI.router
|
|
7
7
|
|
8
8
|
begin
|
9
9
|
exit router.run ARGV
|
10
|
-
|
11
10
|
rescue MenuCommander::Interrupt, Interrupt => e
|
12
11
|
message = e.message
|
13
12
|
message = 'Interrupted... Goodbye' if message.empty?
|
14
13
|
say! "\n#{message}"
|
15
14
|
exit 0
|
16
|
-
|
17
15
|
rescue MenuCommander::Exit => e
|
18
|
-
say
|
16
|
+
say e.message if e.message
|
19
17
|
exit 0
|
20
|
-
|
21
18
|
rescue MenuCommander::MenuNotFound => e
|
22
|
-
say!
|
23
|
-
if e.paths
|
24
|
-
message = "Looked for
|
19
|
+
say! e.message
|
20
|
+
if e.paths && e.config
|
21
|
+
message = "Looked for g`#{e.config}` in"
|
25
22
|
if e.paths.size == 1
|
26
|
-
message += "
|
23
|
+
message += " g`#{e.paths.first}`"
|
27
24
|
say! message
|
28
25
|
else
|
29
26
|
say! message
|
30
27
|
e.paths.each do |path|
|
31
|
-
say! "-
|
28
|
+
say! "- g`#{path}`"
|
32
29
|
end
|
33
30
|
end
|
34
31
|
end
|
35
32
|
exit 1
|
36
|
-
|
37
33
|
rescue => e
|
38
34
|
puts e.backtrace.reverse if ENV['DEBUG']
|
39
|
-
say! "
|
35
|
+
say! "r`#{e.class}: #{e.message}`"
|
40
36
|
exit 1
|
41
|
-
|
42
|
-
end
|
37
|
+
end
|
@@ -2,21 +2,21 @@ require 'mister_bin'
|
|
2
2
|
|
3
3
|
module MenuCommander
|
4
4
|
class Command < MisterBin::Command
|
5
|
-
help
|
5
|
+
help 'Menu Commander'
|
6
6
|
|
7
|
-
usage
|
8
|
-
usage
|
7
|
+
usage 'menu [CONFIG --loop (--dry|--confirm)]'
|
8
|
+
usage 'menu (-h|--help|--version)'
|
9
9
|
|
10
|
-
option
|
11
|
-
option
|
12
|
-
option
|
13
|
-
option
|
10
|
+
option '-d --dry', 'Dry run - do not execute the command at the end, just show it'
|
11
|
+
option '-l --loop', 'Reopen the menu after executing the selected command'
|
12
|
+
option '-c --confirm', 'Show the command before execution and ask for confirmation'
|
13
|
+
option '--version', 'Show version number'
|
14
14
|
|
15
|
-
param
|
15
|
+
param 'CONFIG', 'The name of the menu config file with or without the .yml extension [default: menu]'
|
16
16
|
|
17
|
-
example
|
18
|
-
example
|
19
|
-
example
|
17
|
+
example 'menu --dry'
|
18
|
+
example 'menu production --loop --confirm'
|
19
|
+
example 'menu -ld'
|
20
20
|
|
21
21
|
attr_reader :last_command
|
22
22
|
|
@@ -41,14 +41,14 @@ module MenuCommander
|
|
41
41
|
end
|
42
42
|
|
43
43
|
def verify_sanity
|
44
|
-
raise Exit, VERSION if args['--version']
|
44
|
+
raise Exit, VERSION if args['--version']
|
45
45
|
raise MenuNotFound.new(paths: menu_paths, config: config) unless menu_file
|
46
46
|
end
|
47
47
|
|
48
48
|
def run_looped_menu
|
49
49
|
loop do
|
50
50
|
run_menu
|
51
|
-
say
|
51
|
+
say ''
|
52
52
|
@menu = nil
|
53
53
|
break if ENV['MENU_COMMANDER_ENV'] == 'test'
|
54
54
|
end
|
@@ -59,9 +59,9 @@ module MenuCommander
|
|
59
59
|
@last_command = command
|
60
60
|
|
61
61
|
execute = args['--dry'] ? false : true
|
62
|
-
say "$
|
62
|
+
say "$ m`#{command}`".strip if args['--confirm'] || args['--dry']
|
63
63
|
|
64
|
-
execute = prompt.yes?(
|
64
|
+
execute = prompt.yes?('Execute?') if args['--confirm']
|
65
65
|
success = execute ? system(command) : false
|
66
66
|
|
67
67
|
echo_footer success, command if menu.options.echo
|
@@ -71,13 +71,13 @@ module MenuCommander
|
|
71
71
|
def echo_footer(success, command)
|
72
72
|
if success
|
73
73
|
marker = menu.options.echo_marker_success
|
74
|
-
color =
|
74
|
+
color = 'b'
|
75
75
|
else
|
76
76
|
marker = menu.options.echo_marker_error
|
77
|
-
color =
|
77
|
+
color = 'r'
|
78
78
|
end
|
79
79
|
|
80
|
-
say "
|
80
|
+
say "#{color}`#{marker} #{command}`".strip
|
81
81
|
end
|
82
82
|
|
83
83
|
def menu_file
|
@@ -102,7 +102,7 @@ module MenuCommander
|
|
102
102
|
|
103
103
|
def config
|
104
104
|
result = args['CONFIG'] || 'menu'
|
105
|
-
result +=
|
105
|
+
result += '.yml' unless result.end_with?('.yml')
|
106
106
|
result
|
107
107
|
end
|
108
108
|
|
@@ -2,14 +2,15 @@ module MenuCommander
|
|
2
2
|
class Error < StandardError; end
|
3
3
|
class Interrupt < Interrupt; end
|
4
4
|
class Exit < SystemExit; end
|
5
|
-
|
5
|
+
|
6
6
|
class MenuNotFound < Error
|
7
7
|
# :nocov: - covered by external process
|
8
8
|
attr_reader :paths, :config
|
9
9
|
|
10
|
-
def initialize(message=nil, paths: nil, config: nil)
|
11
|
-
message ||=
|
12
|
-
@paths
|
10
|
+
def initialize(message = nil, paths: nil, config: nil)
|
11
|
+
message ||= 'Could not find menu configuration file'
|
12
|
+
@paths = paths
|
13
|
+
@config = config
|
13
14
|
super message
|
14
15
|
end
|
15
16
|
# :nocov:
|
@@ -17,8 +18,8 @@ module MenuCommander
|
|
17
18
|
|
18
19
|
class ExitMenu < Interrupt
|
19
20
|
# :nocov:
|
20
|
-
def initialize(message=nil)
|
21
|
-
super (message ||
|
21
|
+
def initialize(message = nil)
|
22
|
+
super (message || 'Goodbye')
|
22
23
|
end
|
23
24
|
# :nocov:
|
24
25
|
end
|
@@ -30,4 +31,4 @@ module MenuCommander
|
|
30
31
|
@menu = menu
|
31
32
|
end
|
32
33
|
end
|
33
|
-
end
|
34
|
+
end
|
data/lib/menu_commander/menu.rb
CHANGED
@@ -10,7 +10,7 @@ module MenuCommander
|
|
10
10
|
@config = config
|
11
11
|
end
|
12
12
|
|
13
|
-
def call(menu=nil)
|
13
|
+
def call(menu = nil)
|
14
14
|
menu ||= config['menu']
|
15
15
|
response = select menu
|
16
16
|
response = combine_commands response if response.is_a? Array
|
@@ -21,7 +21,6 @@ module MenuCommander
|
|
21
21
|
rescue MenuNavigation => e
|
22
22
|
puts "\n\n"
|
23
23
|
call e.menu
|
24
|
-
|
25
24
|
end
|
26
25
|
|
27
26
|
def options
|
@@ -75,9 +74,9 @@ module MenuCommander
|
|
75
74
|
|
76
75
|
def get_opts_type(opts)
|
77
76
|
if !opts
|
78
|
-
:free_text
|
79
|
-
elsif options.auto_select
|
80
|
-
:static
|
77
|
+
:free_text
|
78
|
+
elsif options.auto_select && opts.is_a?(Array) && (opts.size == 1)
|
79
|
+
:static
|
81
80
|
else
|
82
81
|
:menu
|
83
82
|
end
|
@@ -102,13 +101,13 @@ module MenuCommander
|
|
102
101
|
case event.key.name
|
103
102
|
when :page_up
|
104
103
|
parent_menu = history.pop
|
105
|
-
raise MenuNavigation
|
104
|
+
raise MenuNavigation, parent_menu if parent_menu
|
106
105
|
|
107
106
|
when :home
|
108
107
|
home_menu = history.first
|
109
108
|
if home_menu
|
110
109
|
@history = []
|
111
|
-
raise MenuNavigation
|
110
|
+
raise MenuNavigation, home_menu
|
112
111
|
end
|
113
112
|
|
114
113
|
end
|
@@ -116,50 +115,44 @@ module MenuCommander
|
|
116
115
|
|
117
116
|
def ask(title)
|
118
117
|
prompt.ask "> #{title}:"
|
119
|
-
|
120
118
|
rescue TTY::Reader::InputInterrupt
|
121
119
|
# :nocov:
|
122
120
|
raise ExitMenu
|
123
121
|
# :nocov:
|
124
|
-
|
125
122
|
end
|
126
123
|
|
127
124
|
def apply_suffix(choices)
|
128
|
-
choices.
|
125
|
+
choices.to_h do |key, value|
|
129
126
|
key = "#{key}#{options.submenu_marker}" if value.is_a? Hash
|
130
127
|
[key, value]
|
131
|
-
end
|
128
|
+
end
|
132
129
|
end
|
133
130
|
|
134
131
|
def enable_filter?(choices)
|
135
|
-
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
-
elsif options.filter.is_a? Numeric
|
140
|
-
choices.size > options.filter
|
132
|
+
case options.filter
|
133
|
+
when true then true
|
134
|
+
when false then false
|
135
|
+
when Numeric then choices.size > options.filter
|
141
136
|
else
|
142
137
|
choices.size > options.page_size
|
143
138
|
end
|
144
139
|
end
|
145
140
|
|
146
|
-
def select(choices, title=nil)
|
141
|
+
def select(choices, title = nil)
|
147
142
|
title = title ? "#{options.title_marker} #{title}:" : options.title_marker
|
148
|
-
choices = apply_suffix choices if options.submenu_marker
|
143
|
+
choices = apply_suffix choices if options.submenu_marker && choices.is_a?(Hash)
|
149
144
|
select! choices, title
|
150
145
|
end
|
151
146
|
|
152
|
-
def select!(choices, title)
|
153
|
-
prompt.select title, choices,
|
154
|
-
symbols:
|
155
|
-
per_page: options.page_size,
|
156
|
-
filter:
|
157
|
-
|
147
|
+
def select!(choices, title)
|
148
|
+
prompt.select title, choices,
|
149
|
+
symbols: { marker: options.select_marker },
|
150
|
+
per_page: options.page_size,
|
151
|
+
filter: enable_filter?(choices)
|
158
152
|
rescue TTY::Reader::InputInterrupt
|
159
153
|
# :nocov:
|
160
154
|
raise ExitMenu
|
161
155
|
# :nocov:
|
162
|
-
|
163
156
|
end
|
164
157
|
end
|
165
|
-
end
|
158
|
+
end
|
@@ -4,22 +4,22 @@ module MenuCommander
|
|
4
4
|
|
5
5
|
def initialize(options)
|
6
6
|
options ||= {}
|
7
|
-
options.transform_keys!
|
7
|
+
options.transform_keys!(&:to_sym)
|
8
8
|
@options = default_options.merge options
|
9
|
-
end
|
9
|
+
end
|
10
10
|
|
11
11
|
def default_options
|
12
12
|
@default_options ||= {
|
13
|
-
auto_select:
|
14
|
-
echo:
|
13
|
+
auto_select: true,
|
14
|
+
echo: false,
|
15
15
|
echo_marker_success: '✓',
|
16
|
-
echo_marker_error:
|
17
|
-
filter:
|
18
|
-
header:
|
19
|
-
page_size:
|
20
|
-
select_marker:
|
21
|
-
submenu_marker:
|
22
|
-
title_marker:
|
16
|
+
echo_marker_error: '✗',
|
17
|
+
filter: 'auto',
|
18
|
+
header: false,
|
19
|
+
page_size: 10,
|
20
|
+
select_marker: '⯈',
|
21
|
+
submenu_marker: ' ⯆',
|
22
|
+
title_marker: '▌', # ➤ ❚ ✚
|
23
23
|
}
|
24
24
|
end
|
25
25
|
|
@@ -27,8 +27,8 @@ module MenuCommander
|
|
27
27
|
respond_to?(method) ? options[method] : super
|
28
28
|
end
|
29
29
|
|
30
|
-
def respond_to_missing?(method_name, include_private=false)
|
30
|
+
def respond_to_missing?(method_name, include_private = false)
|
31
31
|
options.has_key?(method_name) || super
|
32
32
|
end
|
33
33
|
end
|
34
|
-
end
|
34
|
+
end
|
@@ -1,3 +1,3 @@
|
|
1
1
|
module MenuCommander
|
2
|
-
VERSION =
|
3
|
-
end
|
2
|
+
VERSION = '0.2.7'
|
3
|
+
end
|
data/lib/menu_commander.rb
CHANGED
metadata
CHANGED
@@ -1,71 +1,77 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: menu_commander
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2.
|
4
|
+
version: 0.2.7
|
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:
|
11
|
+
date: 2023-01-31 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
|
-
name:
|
14
|
+
name: colsole
|
15
15
|
requirement: !ruby/object:Gem::Requirement
|
16
16
|
requirements:
|
17
|
-
- - "
|
17
|
+
- - ">="
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version:
|
19
|
+
version: 0.8.1
|
20
|
+
- - "<"
|
21
|
+
- !ruby/object:Gem::Version
|
22
|
+
version: '2'
|
20
23
|
type: :runtime
|
21
24
|
prerelease: false
|
22
25
|
version_requirements: !ruby/object:Gem::Requirement
|
23
26
|
requirements:
|
24
|
-
- - "
|
27
|
+
- - ">="
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: 0.8.1
|
30
|
+
- - "<"
|
25
31
|
- !ruby/object:Gem::Version
|
26
|
-
version: '
|
32
|
+
version: '2'
|
27
33
|
- !ruby/object:Gem::Dependency
|
28
|
-
name:
|
34
|
+
name: extended_yaml
|
29
35
|
requirement: !ruby/object:Gem::Requirement
|
30
36
|
requirements:
|
31
37
|
- - "~>"
|
32
38
|
- !ruby/object:Gem::Version
|
33
|
-
version: '0.
|
39
|
+
version: '0.2'
|
34
40
|
type: :runtime
|
35
41
|
prerelease: false
|
36
42
|
version_requirements: !ruby/object:Gem::Requirement
|
37
43
|
requirements:
|
38
44
|
- - "~>"
|
39
45
|
- !ruby/object:Gem::Version
|
40
|
-
version: '0.
|
46
|
+
version: '0.2'
|
41
47
|
- !ruby/object:Gem::Dependency
|
42
|
-
name:
|
48
|
+
name: mister_bin
|
43
49
|
requirement: !ruby/object:Gem::Requirement
|
44
50
|
requirements:
|
45
51
|
- - "~>"
|
46
52
|
- !ruby/object:Gem::Version
|
47
|
-
version: 0.
|
53
|
+
version: '0.7'
|
48
54
|
type: :runtime
|
49
55
|
prerelease: false
|
50
56
|
version_requirements: !ruby/object:Gem::Requirement
|
51
57
|
requirements:
|
52
58
|
- - "~>"
|
53
59
|
- !ruby/object:Gem::Version
|
54
|
-
version: 0.
|
60
|
+
version: '0.7'
|
55
61
|
- !ruby/object:Gem::Dependency
|
56
|
-
name:
|
62
|
+
name: tty-prompt
|
57
63
|
requirement: !ruby/object:Gem::Requirement
|
58
64
|
requirements:
|
59
65
|
- - "~>"
|
60
66
|
- !ruby/object:Gem::Version
|
61
|
-
version: '0.
|
67
|
+
version: '0.23'
|
62
68
|
type: :runtime
|
63
69
|
prerelease: false
|
64
70
|
version_requirements: !ruby/object:Gem::Requirement
|
65
71
|
requirements:
|
66
72
|
- - "~>"
|
67
73
|
- !ruby/object:Gem::Version
|
68
|
-
version: '0.
|
74
|
+
version: '0.23'
|
69
75
|
description: Easily create menus for any command line tool using simple YAML configuration
|
70
76
|
email: db@dannyben.com
|
71
77
|
executables:
|
@@ -81,12 +87,12 @@ files:
|
|
81
87
|
- lib/menu_commander/exceptions.rb
|
82
88
|
- lib/menu_commander/menu.rb
|
83
89
|
- lib/menu_commander/menu_options.rb
|
84
|
-
- lib/menu_commander/polyfills/hash.rb
|
85
90
|
- lib/menu_commander/version.rb
|
86
91
|
homepage: https://github.com/dannyben/menu_commander
|
87
92
|
licenses:
|
88
93
|
- MIT
|
89
|
-
metadata:
|
94
|
+
metadata:
|
95
|
+
rubygems_mfa_required: 'true'
|
90
96
|
post_install_message:
|
91
97
|
rdoc_options: []
|
92
98
|
require_paths:
|
@@ -95,14 +101,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
95
101
|
requirements:
|
96
102
|
- - ">="
|
97
103
|
- !ruby/object:Gem::Version
|
98
|
-
version: 2.
|
104
|
+
version: 2.7.0
|
99
105
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
100
106
|
requirements:
|
101
107
|
- - ">="
|
102
108
|
- !ruby/object:Gem::Version
|
103
109
|
version: '0'
|
104
110
|
requirements: []
|
105
|
-
rubygems_version: 3.
|
111
|
+
rubygems_version: 3.4.5
|
106
112
|
signing_key:
|
107
113
|
specification_version: 4
|
108
114
|
summary: Create menus for any CLI tool
|