menu_commander 0.0.1 → 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +20 -2
- data/bin/menu +21 -2
- data/lib/menu_commander/command.rb +19 -4
- data/lib/menu_commander/exceptions.rb +7 -2
- data/lib/menu_commander/menu.rb +12 -11
- data/lib/menu_commander/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 4cf72e4a3375daaa4a0693a693d24cd8bdd2b16ddaff9d5696c8b84cba683ca7
|
4
|
+
data.tar.gz: 1238ecd337b8c51511b008ceda05160867b57dc9a64adcdaef57eb84c937d69c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 46e4e917ce083cde286e75e1673bfb412ca315716d924a0401787bfa04c1cc0de729ddbdebd6a5d8468ce5573848d61ef0e127029fb91891d3d84b079ac91795
|
7
|
+
data.tar.gz: 58c9e748ea7e34baa187bb26213fa169f8adba2c022fa1c88ffd102c0e89135c7b4d278173cef28b5a2eb6ebc08e2561ff4df4b46cc3db7ce6272413e85dc5ef
|
data/README.md
CHANGED
@@ -3,7 +3,7 @@ Menu Commander
|
|
3
3
|
|
4
4
|
[![Gem Version](https://badge.fury.io/rb/menu_commander.svg)](https://badge.fury.io/rb/menu_commander)
|
5
5
|
[![Build Status](https://travis-ci.com/DannyBen/menu_commander.svg?branch=master)](https://travis-ci.com/DannyBen/menu_commander)
|
6
|
-
[![Maintainability](https://api.codeclimate.com/v1/badges
|
6
|
+
[![Maintainability](https://api.codeclimate.com/v1/badges/aa048e0f2cf1655261ac/maintainability)](https://codeclimate.com/github/DannyBen/menu_commander/maintainability)
|
7
7
|
|
8
8
|
---
|
9
9
|
|
@@ -47,7 +47,7 @@ Running it, looks like this:
|
|
47
47
|
![Demo](/demo/demo.gif)
|
48
48
|
|
49
49
|
|
50
|
-
Features
|
50
|
+
Menu Configuration Features
|
51
51
|
--------------------------------------------------
|
52
52
|
|
53
53
|
All features have an example configuration in the
|
@@ -145,3 +145,21 @@ menu:
|
|
145
145
|
branch: git branch
|
146
146
|
```
|
147
147
|
|
148
|
+
Menu File Location
|
149
|
+
--------------------------------------------------
|
150
|
+
|
151
|
+
By default, menu files are looked for in the current working directory.
|
152
|
+
|
153
|
+
You may instruct Menu Commander to look in additional locations by setting
|
154
|
+
the `MENU_PATH` environment variable to one or more paths. Note that when
|
155
|
+
using this method, Menu Commander will *not* look in the current directory,
|
156
|
+
unless you include it in `MENU_PATH`, like this:
|
157
|
+
|
158
|
+
```shell
|
159
|
+
$ export MENU_PATH=.:$HOME/menus:/etc/menus
|
160
|
+
```
|
161
|
+
|
162
|
+
If you wish this setting to be permanent, add it to your `.bashrc` or your
|
163
|
+
preferred initialization script.
|
164
|
+
|
165
|
+
|
data/bin/menu
CHANGED
@@ -7,11 +7,30 @@ router = MenuCommander::CLI.router
|
|
7
7
|
|
8
8
|
begin
|
9
9
|
exit router.run ARGV
|
10
|
+
|
11
|
+
rescue MenuCommander::Interrupt => e
|
12
|
+
say! "\n#{e.message}"
|
13
|
+
exit 0
|
14
|
+
|
10
15
|
rescue MenuCommander::MenuNotFound => e
|
11
|
-
say! "
|
12
|
-
|
16
|
+
say! "#{e.message}"
|
17
|
+
if e.paths and e.config
|
18
|
+
message = "Looked for !txtgrn!#{e.config}.yml!txtrst! in"
|
19
|
+
if e.paths.size == 1
|
20
|
+
message += " !txtgrn!#{e.paths.first}"
|
21
|
+
say! message
|
22
|
+
else
|
23
|
+
say! message
|
24
|
+
e.paths.each do |path|
|
25
|
+
say! "- !txtgrn!#{path}"
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
29
|
+
exit 1
|
30
|
+
|
13
31
|
rescue => e
|
14
32
|
puts e.backtrace.reverse if ENV['DEBUG']
|
15
33
|
say! "!txtred!#{e.class}: #{e.message}"
|
16
34
|
exit 1
|
35
|
+
|
17
36
|
end
|
@@ -12,7 +12,7 @@ module MenuCommander
|
|
12
12
|
param "CONFIG", "The name of the menu config file without the .yml extension [default: menu]"
|
13
13
|
|
14
14
|
def run
|
15
|
-
raise MenuNotFound unless
|
15
|
+
raise MenuNotFound.new(paths: menu_paths, config: config) unless menu_file
|
16
16
|
|
17
17
|
if args['--dry']
|
18
18
|
say "$ !txtpur!#{command}"
|
@@ -32,12 +32,27 @@ module MenuCommander
|
|
32
32
|
private
|
33
33
|
|
34
34
|
def menu_file
|
35
|
-
|
35
|
+
@menu_file ||= menu_file!
|
36
|
+
end
|
37
|
+
|
38
|
+
def menu_file!
|
39
|
+
menu_paths.each do |dir|
|
40
|
+
file = "#{dir}/#{config}.yml"
|
41
|
+
return file if File.exist? file
|
42
|
+
end
|
43
|
+
nil
|
44
|
+
end
|
45
|
+
|
46
|
+
def menu_paths
|
47
|
+
menu_env_path.split File::PATH_SEPARATOR
|
48
|
+
end
|
49
|
+
|
50
|
+
def menu_env_path
|
51
|
+
ENV['MENU_PATH'] || '.'
|
36
52
|
end
|
37
53
|
|
38
54
|
def config
|
39
55
|
config = args['CONFIG'] || 'menu'
|
40
56
|
end
|
41
|
-
|
42
57
|
end
|
43
|
-
end
|
58
|
+
end
|
@@ -1,10 +1,15 @@
|
|
1
1
|
module MenuCommander
|
2
2
|
class Error < StandardError; end
|
3
|
+
class Interrupt < Interrupt; end
|
3
4
|
|
4
5
|
class MenuNotFound < Error
|
5
6
|
# :nocov: - covered by external process
|
6
|
-
|
7
|
-
|
7
|
+
attr_reader :paths, :config
|
8
|
+
|
9
|
+
def initialize(message = nil, paths: nil, config: nil)
|
10
|
+
message ||= "Could not find menu configuration file"
|
11
|
+
@paths, @config = paths, config
|
12
|
+
super message
|
8
13
|
end
|
9
14
|
# :nocov:
|
10
15
|
end
|
data/lib/menu_commander/menu.rb
CHANGED
@@ -36,14 +36,13 @@ module MenuCommander
|
|
36
36
|
end
|
37
37
|
|
38
38
|
def get_user_response(key)
|
39
|
-
opts =
|
40
|
-
opts
|
39
|
+
opts = get_opts key
|
40
|
+
opts ? select(opts, key) : ask(key)
|
41
|
+
end
|
41
42
|
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
ask(key)
|
46
|
-
end
|
43
|
+
def get_opts(key)
|
44
|
+
opts = args ? args[key] : nil
|
45
|
+
opts.is_a?(String) ? `#{opts}`.split("\n") : opts
|
47
46
|
end
|
48
47
|
|
49
48
|
def prompt
|
@@ -52,11 +51,12 @@ module MenuCommander
|
|
52
51
|
|
53
52
|
def ask(title)
|
54
53
|
prompt.ask "> #{title}:"
|
54
|
+
|
55
55
|
rescue TTY::Reader::InputInterrupt
|
56
56
|
# :nocov:
|
57
|
-
|
58
|
-
exit
|
57
|
+
raise Interrupt, "Goodbye"
|
59
58
|
# :nocov:
|
59
|
+
|
60
60
|
end
|
61
61
|
|
62
62
|
def select(options, title = nil)
|
@@ -64,11 +64,12 @@ module MenuCommander
|
|
64
64
|
menu_config = { marker: '>', per_page: 10 }
|
65
65
|
menu_config['filter'] = true if options.size > 10
|
66
66
|
prompt.select title, options, menu_config
|
67
|
+
|
67
68
|
rescue TTY::Reader::InputInterrupt
|
68
69
|
# :nocov:
|
69
|
-
|
70
|
-
exit
|
70
|
+
raise Interrupt, "Goodbye"
|
71
71
|
# :nocov:
|
72
|
+
|
72
73
|
end
|
73
74
|
end
|
74
75
|
end
|