cl-magic 1.2.0 → 1.2.1
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/Gemfile.lock +1 -1
- data/lib/cl/magic/cl-dk-parts +18 -10
- data/lib/cl/magic/common/parse_and_pick.rb +6 -6
- data/lib/cl/magic/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: bae4cae1197514890ab80299d8f0379f89661e2b8d731ac714e0b99cdcd7f4ba
|
4
|
+
data.tar.gz: 47588e897f238d68a9edbbb3bd13ca418018c85aade5006bd9ea7c1f742bf192
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 1446ea456116138116613b93d732ee02dfead51c66df386be273b36dc660bc762892d9bc6b110cadab620d4b6023922ce4a5e79c3261230ddfffd8c685f577db
|
7
|
+
data.tar.gz: bc3d680c504cf92f88ed5da9743068256c9245234d86e656c272b168e69ea611d45a8ed0d976ea6033738bd4eb7e69fd3cbd38cd10238e3030632450db53699f
|
data/Gemfile.lock
CHANGED
data/lib/cl/magic/cl-dk-parts
CHANGED
@@ -7,6 +7,7 @@ require 'tty-command'
|
|
7
7
|
|
8
8
|
require 'cl/magic/common/common_options.rb'
|
9
9
|
require 'cl/magic/common/logging.rb'
|
10
|
+
require 'cl/magic/common/parse_and_pick.rb'
|
10
11
|
|
11
12
|
require_relative 'dk/help_printer'
|
12
13
|
require_relative 'dk/yaml_arg_munger'
|
@@ -47,7 +48,7 @@ def do_set(options)
|
|
47
48
|
yield_all_parts do |dk_parts_hash|
|
48
49
|
parts = ARGV[1..]
|
49
50
|
|
50
|
-
if parts.any?
|
51
|
+
if parts.any? or options[:action] == :set
|
51
52
|
|
52
53
|
# validate parts
|
53
54
|
parts.each do |part|
|
@@ -67,6 +68,11 @@ def do_set(options)
|
|
67
68
|
parts = ARGV[1..]
|
68
69
|
case options[:action]
|
69
70
|
when :set
|
71
|
+
unless parts.any?
|
72
|
+
options = dk_parts_hash.keys.collect {|k| [k.ljust(25, ' '), dk_parts_hash[k]['help'].rjust(25, ' ')]}
|
73
|
+
selected_parts = pick_multiple_result(options, "Which parts?", nil, false)
|
74
|
+
parts = selected_parts.collect {|o| o.first.strip}
|
75
|
+
end
|
70
76
|
File.open(filepath, 'w') { |file| file.write(parts.to_yaml) }
|
71
77
|
@logger.success "parts set"
|
72
78
|
when :add
|
@@ -105,26 +111,28 @@ def do_clear(options)
|
|
105
111
|
end
|
106
112
|
end
|
107
113
|
|
114
|
+
def get_saved_parts()
|
115
|
+
filepath = get_save_parts_filepath()
|
116
|
+
return YAML.load_file(filepath) if File.exist?(filepath)
|
117
|
+
return []
|
118
|
+
end
|
119
|
+
|
108
120
|
def do_list_saved_parts(options)
|
109
121
|
|
110
122
|
is_tty = $stdout.isatty
|
111
123
|
|
112
124
|
yield_all_parts do |dk_parts_hash|
|
113
125
|
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
# merge
|
118
|
-
if File.exist?(filepath)
|
119
|
-
saved_parts = YAML.load_file(filepath)
|
120
|
-
|
126
|
+
saved_parts = get_saved_parts()
|
127
|
+
if saved_parts.any?
|
121
128
|
puts "" if is_tty
|
122
129
|
dk_parts_hash.keys.each do |part|
|
123
130
|
if is_tty
|
131
|
+
part_desc = "#{part.ljust(27, ' ')} | #{dk_parts_hash[part]['help']}"
|
124
132
|
if saved_parts.include? part
|
125
|
-
puts "* #{
|
133
|
+
puts "* #{part_desc}"
|
126
134
|
else
|
127
|
-
puts " #{
|
135
|
+
puts " #{part_desc}"
|
128
136
|
end
|
129
137
|
else
|
130
138
|
puts part if saved_parts.include? part # terminal only
|
@@ -22,7 +22,7 @@ def parse_table_results(command, error_message, num_headers=1, split=nil, workin
|
|
22
22
|
# run command
|
23
23
|
TTY::Command.new(:printer => :null).run(command).each { |line| results << line.split(split) }
|
24
24
|
num_headers.times { results.delete_at(0) } # remove header
|
25
|
-
|
25
|
+
|
26
26
|
if not results.any?
|
27
27
|
@logger.error error_message
|
28
28
|
exit(1)
|
@@ -33,7 +33,7 @@ end
|
|
33
33
|
|
34
34
|
#
|
35
35
|
# Prompt the user to pick a single result
|
36
|
-
#
|
36
|
+
#
|
37
37
|
# results - and array of arrays
|
38
38
|
# prompt_message - the message for our picker
|
39
39
|
# exact - if provided, we'll return whatever matches this exactly
|
@@ -41,7 +41,7 @@ end
|
|
41
41
|
#
|
42
42
|
|
43
43
|
def pick_single_result(results, prompt_message, exact=nil, default=nil, selection_index=0)
|
44
|
-
|
44
|
+
|
45
45
|
# exact match?
|
46
46
|
results = results.select {|r| r[selection_index] == exact} if exact
|
47
47
|
|
@@ -63,7 +63,7 @@ def pick_single_result(results, prompt_message, exact=nil, default=nil, selectio
|
|
63
63
|
end
|
64
64
|
|
65
65
|
|
66
|
-
def pick_multiple_result(results, prompt_message, exacts=nil)
|
66
|
+
def pick_multiple_result(results, prompt_message, exacts=nil, echo=true)
|
67
67
|
|
68
68
|
# exact match?
|
69
69
|
return results.select {|r| exacts.split(',').include? r.first} if exacts
|
@@ -71,11 +71,11 @@ def pick_multiple_result(results, prompt_message, exacts=nil)
|
|
71
71
|
# 0 or 1 result?
|
72
72
|
return results if results.count < 2
|
73
73
|
|
74
|
-
selections = TTY::Prompt.new(interrupt: :exit).multi_select(prompt_message, filter: true, per_page: 20) do |menu|
|
74
|
+
selections = TTY::Prompt.new(interrupt: :exit).multi_select(prompt_message, filter: true, per_page: 20, echo: echo) do |menu|
|
75
75
|
results.each do |result|
|
76
76
|
menu.choice result.join(' | '), result.first
|
77
77
|
end
|
78
78
|
end
|
79
79
|
|
80
80
|
return results.select {|r| selections.include? r.first}
|
81
|
-
end
|
81
|
+
end
|
data/lib/cl/magic/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: cl-magic
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.2.
|
4
|
+
version: 1.2.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Don Najd
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2023-08-
|
11
|
+
date: 2023-08-21 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rake
|