cl-magic 1.2.0 → 1.2.1

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: e7f003696dcc6355ea8ee76ac94c01d8d8b324032a1c5214352de53ef0d90fd8
4
- data.tar.gz: bf5e85e1e57a35a840eae95707af831e8079ce0fc85b1da87e229c89fb20c292
3
+ metadata.gz: bae4cae1197514890ab80299d8f0379f89661e2b8d731ac714e0b99cdcd7f4ba
4
+ data.tar.gz: 47588e897f238d68a9edbbb3bd13ca418018c85aade5006bd9ea7c1f742bf192
5
5
  SHA512:
6
- metadata.gz: 80a97ad2355650603ac4627fc9fecc11cf5b7f558f1a835c3824d579de3bb82ac627a49d0f46cac119518a12b0215f107467e5753dff202d003d7bd578dd6f5a
7
- data.tar.gz: 65023f6827983ddcd9f4fddca778f1cd8df8566764a943f6b7e0d6bce7b81743358262900b63964a7e5f511499293573c46bb5ce8f4e73f049f739ecb50be71b
6
+ metadata.gz: 1446ea456116138116613b93d732ee02dfead51c66df386be273b36dc660bc762892d9bc6b110cadab620d4b6023922ce4a5e79c3261230ddfffd8c685f577db
7
+ data.tar.gz: bc3d680c504cf92f88ed5da9743068256c9245234d86e656c272b168e69ea611d45a8ed0d976ea6033738bd4eb7e69fd3cbd38cd10238e3030632450db53699f
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- cl-magic (1.2.0)
4
+ cl-magic (1.2.1)
5
5
  activesupport
6
6
  baran
7
7
  concurrent-ruby
@@ -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
- saved_part_keys = []
115
- filepath = get_save_parts_filepath()
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 "* #{part}"
133
+ puts "* #{part_desc}"
126
134
  else
127
- puts " #{part}"
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
@@ -2,6 +2,6 @@
2
2
 
3
3
  module Cl
4
4
  module Magic
5
- VERSION = "1.2.0"
5
+ VERSION = "1.2.1"
6
6
  end
7
7
  end
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.0
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-17 00:00:00.000000000 Z
11
+ date: 2023-08-21 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rake