tabry 0.2.6 → 0.3.0

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.
Files changed (37) hide show
  1. checksums.yaml +4 -4
  2. data/bin/tabry-generate-bash-complete +2 -3
  3. data/bin/tabry-generate-fish-complete +2 -3
  4. data/lib/tabry/cli/all_in_one.rb +16 -13
  5. data/lib/tabry/cli/arg_proxy.rb +1 -1
  6. data/lib/tabry/cli/builder.rb +2 -0
  7. data/lib/tabry/cli/util.rb +1 -1
  8. data/lib/tabry/config_builder/top_level_builder.rb +1 -0
  9. data/lib/tabry/config_loader.rb +2 -2
  10. data/lib/tabry/models/config_list.rb +5 -0
  11. data/lib/tabry/models/config_object.rb +17 -0
  12. data/lib/tabry/models/config_string_hash.rb +5 -0
  13. data/lib/tabry/models/include_arg.rb +3 -1
  14. data/lib/tabry/models/subs_list.rb +0 -1
  15. data/lib/tabry/options_finder.rb +38 -10
  16. data/lib/tabry/replty/builder.rb +1 -1
  17. data/lib/tabry/result.rb +18 -2
  18. data/lib/tabry/runner.rb +6 -1
  19. data/lib/tabry/shells/bash.rb +2 -2
  20. data/lib/tabry/shells/fish/wrapper.rb +4 -6
  21. data/lib/tabry/shells/fish.rb +4 -4
  22. data/lib/tabry/version.rb +3 -1
  23. data/spec/fixtures/vehicles.tabry +1 -1
  24. data/spec/fixtures/vehicles.yaml +1 -1
  25. data/spec/tabry/cli/all_in_one_spec.rb +7 -0
  26. data/spec/tabry/config_builder_spec.rb +5 -1
  27. data/spec/tabry/machine_spec.rb +1 -1
  28. data/spec/tabry/models/config_spec.rb +6 -0
  29. data/spec/tabry/models/dir_option_spec.rb +1 -1
  30. data/spec/tabry/models/file_option_spec.rb +1 -1
  31. data/spec/tabry/models/shell_option_spec.rb +1 -1
  32. data/spec/tabry/options_finder_spec.rb +5 -0
  33. data/spec/tabry/replty/builder_spec.rb +7 -5
  34. data/spec/tabry/runner_spec.rb +3 -1
  35. data/spec/tabry/shells/bash_spec.rb +4 -3
  36. data/tabry.gemspec +1 -1
  37. metadata +3 -3
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 7733876522770c3037de86e663ddadd59cf1a86b2ddb1bc993934789e5b8d34a
4
- data.tar.gz: 383673dc7f2ba427e70808fc08484829db28cd5b2c263b21ed1a4971ee2427be
3
+ metadata.gz: fb391cd439ebe097e13df65ff4a99f2911abd2d53b9c81e8283b8d5af94282b9
4
+ data.tar.gz: ed3bc83d0f19fa9efee82a7cc6ec5cbd37fd34f602cb9915b78fbeeb0e0ddea9
5
5
  SHA512:
6
- metadata.gz: e3f75ff33d1b2d3c9e959debc066a672687b906a64a7b414ed57091878cb4ede0ae815d18c563ea619be7ca148bc51c2a571d9cb4075ff4a10ca0c05e64a97cd
7
- data.tar.gz: 29d82a30fe87411c11c97287bd6af5f1fd279bf2f1a1e44890273c7844d6dd5e0f35916bf4756f2c9fbfbc84f9e6a206862f8d73addbae14cce90666b2b16f89
6
+ metadata.gz: ee6f71b46c334b5c2a50ed46c9d6a2930d9b39d3d9dac42ed158ba5b1f94a3b850d485794169e1794f72d54333813b1f10b6d816a557c36d8830ec126524ff74
7
+ data.tar.gz: fa871318216d9258fc5a9dcbe62ee9b7a9e52922cde2986a6d493025b721753b0b452b8f58ac5157925bfebcddee009289904c676a53ed6d00e2d6b6f4addf98
@@ -1,4 +1,5 @@
1
1
  #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
2
3
 
3
4
  require_relative "../lib/tabry/cli/all_in_one"
4
5
  require_relative "../lib/tabry/shells/bash"
@@ -23,9 +24,7 @@ Tabry::CLI::AllInOne.run do
23
24
  puts Tabry::Shells::Bash.generate(
24
25
  args.command_name,
25
26
  args.tabry_json_path,
26
- uniq_fn_id: flags.uniq_fn_id,
27
+ uniq_fn_id: flags.uniq_fn_id
27
28
  )
28
29
  end
29
30
  end
30
-
31
-
@@ -1,4 +1,5 @@
1
1
  #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
2
3
 
3
4
  require_relative "../lib/tabry/cli/all_in_one"
4
5
  require_relative "../lib/tabry/shells/fish"
@@ -23,9 +24,7 @@ Tabry::CLI::AllInOne.run do
23
24
  puts Tabry::Shells::Fish.generate(
24
25
  args.command_name,
25
26
  args.tabry_json_path,
26
- uniq_fn_id: flags.uniq_fn_id,
27
+ uniq_fn_id: flags.uniq_fn_id
27
28
  )
28
29
  end
29
30
  end
30
-
31
-
@@ -45,6 +45,11 @@ module Tabry
45
45
 
46
46
  def self.define_completion_methods(cli_class, config, cmd_name: nil)
47
47
  cli_class.module_eval do
48
+ define_method :completion__json do
49
+ require "json"
50
+ # Result is flattened/includes squashed (ConfigList#to_a I think calls flatten), so remove the includes
51
+ puts config.as_json.except(:arg_includes, :option_includes).to_json
52
+ end
48
53
 
49
54
  define_method :completion__bash do
50
55
  require_relative "../shells/bash"
@@ -88,18 +93,16 @@ module Tabry
88
93
 
89
94
  # If we recognize command is going to be a completion command, fast track and
90
95
  # run completion now
91
- if run_completion
92
- if ARGV.first == "completion"
93
- fish_mode = ENV.fetch("TABRY_FISH_MODE", false)
94
- if fish_mode
95
- require_relative "../shells/fish/wrapper"
96
- Tabry::Fish::Wrapper.run(ARGV[1], ARGV[2], config: config)
97
- else
98
- require_relative "../shells/bash/wrapper"
99
- Tabry::Bash::Wrapper.run(ARGV[1], ARGV[2], config: config)
100
- end
101
- exit
96
+ if run_completion && (ARGV.first == "completion")
97
+ fish_mode = ENV.fetch("TABRY_FISH_MODE", false)
98
+ if fish_mode
99
+ require_relative "../shells/fish/wrapper"
100
+ Tabry::Fish::Wrapper.run(ARGV[1], ARGV[2], config: config)
101
+ else
102
+ require_relative "../shells/bash/wrapper"
103
+ Tabry::Bash::Wrapper.run(ARGV[1], ARGV[2], config: config)
102
104
  end
105
+ exit
103
106
  end
104
107
 
105
108
  # If we recognize there is a "completion" subcommand, add completion
@@ -111,8 +114,8 @@ module Tabry
111
114
  Tabry::CLI::Builder.new(config, cli)
112
115
  end
113
116
 
114
- def self.run(**kwargs, &blk)
115
- build(**kwargs, &blk).run(ARGV)
117
+ def self.run(...)
118
+ build(...).run(ARGV)
116
119
  end
117
120
  end
118
121
  end
@@ -44,7 +44,7 @@ module Tabry
44
44
  end
45
45
 
46
46
  def <=>(*args)
47
- @args.<=>(*args)
47
+ @args.send(:<=>, *args)
48
48
  end
49
49
 
50
50
  def method_missing(met)
@@ -3,6 +3,7 @@
3
3
  require_relative "../runner"
4
4
  require_relative "../util"
5
5
  require_relative "internals"
6
+ require_relative "base"
6
7
 
7
8
  # Responsible for building the CLI object, making a Runner to parse the
8
9
  # arguments, and running the proper action method of the CLI object.
@@ -56,6 +57,7 @@ module Tabry
56
57
 
57
58
  def instantiate_cli(klass, internals)
58
59
  return klass unless klass.is_a?(Class)
60
+ raise "CLI class must inherit from Tabry::CLI::Base" unless klass < Tabry::CLI::Base
59
61
 
60
62
  state = internals.state
61
63
  klass.new(state.flags, state.args, internals.result.named_args, internals)
@@ -20,7 +20,7 @@ module Tabry
20
20
  Shellwords.escape(arg)
21
21
  end
22
22
  end
23
- cmdline = cmdline % args
23
+ cmdline %= args
24
24
  cmdline = "{ #{cmdline} ;} 2>&1" if merge_stderr
25
25
 
26
26
  warn cmdline if echo || echo_only
@@ -23,6 +23,7 @@ module Tabry
23
23
  def completion
24
24
  sub :completion do
25
25
  desc "Get tab completion shell config"
26
+ sub :json, "Get flattened tabry JSON config for command (experimental)"
26
27
  sub :bash, "Get tab completion for bash or zsh"
27
28
  sub :fish, "Get tab completion for fish"
28
29
  arg :cmd_line, "(for internal usage, when used instead of subcommand) full command line for getting completion options"
@@ -19,7 +19,7 @@ module Tabry
19
19
  end
20
20
 
21
21
  def load
22
- return load_from_file(name) if name =~ /\.json$/i || name =~ /\.ya?ml$/i
22
+ return load_from_file(name) if name =~ /json$/i || name =~ /\.ya?ml$/i
23
23
 
24
24
  load_paths.each do |path|
25
25
  EXTENSIONS.each do |extension|
@@ -48,7 +48,7 @@ module Tabry
48
48
  end
49
49
 
50
50
  def load_from_file(filename)
51
- if filename =~ /\.json$/
51
+ if filename =~ /json$/
52
52
  require "json"
53
53
  Tabry::Models::Config.new(raw: JSON.parse(File.read(filename)))
54
54
  elsif filename =~ /\.ya?ml$/
@@ -24,6 +24,11 @@ module Tabry
24
24
  flatten
25
25
  end
26
26
 
27
+ def as_json
28
+ val = to_a.map { ConfigObject.as_json(_1) }
29
+ val.empty? ? nil : val
30
+ end
31
+
27
32
  def flatten
28
33
  @flatten ||= unflattened.map(&:flatten).flatten
29
34
  end
@@ -73,6 +73,23 @@ module Tabry
73
73
  assert_of_class(key, val, [TrueClass, FalseClass])
74
74
  val
75
75
  end
76
+
77
+ def as_json
78
+ self.class::FIELDS.to_h do |k, _|
79
+ raw_val = send(k)
80
+ [k, ConfigObject.as_json(raw_val)]
81
+ end.compact
82
+ end
83
+
84
+ def self.as_json(val)
85
+ if [ConfigObject, ConfigList, ConfigStringHash].any? { val.is_a?(_1) }
86
+ val.as_json
87
+ elsif val.is_a?(Array)
88
+ val.map { as_json(_1) }
89
+ else
90
+ val
91
+ end
92
+ end
76
93
  end
77
94
  end
78
95
  end
@@ -39,6 +39,11 @@ module Tabry
39
39
  def keys
40
40
  to_h.keys
41
41
  end
42
+
43
+ def as_json
44
+ val = to_h.transform_values { ConfigObject.as_json(_1) }
45
+ val.empty? ? nil : val
46
+ end
42
47
  end
43
48
  end
44
49
  end
@@ -11,7 +11,9 @@ module Tabry
11
11
  end
12
12
 
13
13
  def flatten
14
- _root.arg_includes[include_name].args.flatten
14
+ inc = _root.arg_includes[include_name]
15
+ raise "no include found for #{include_name}" unless inc
16
+ inc.args.flatten
15
17
  end
16
18
  end
17
19
  end
@@ -33,7 +33,6 @@ module Tabry
33
33
  end
34
34
  .compact
35
35
  end
36
-
37
36
  end
38
37
  end
39
38
  end
@@ -28,11 +28,45 @@ module Tabry
28
28
  current_flag: result.state.current_flag
29
29
  }.to_json
30
30
 
31
- send(:"options_#{state.mode}", token || "")
31
+ send(
32
+ { subcommand: :options_subcommand, flagarg: :options_flagarg }[state.mode],
33
+ token || ""
34
+ )
32
35
  ensure
33
36
  ENV["TABRY_AUTOCOMPLETE_STATE"] = before_env
34
37
  end
35
38
 
39
+ # Descriptions of what is expected; particularly, argument names and descriptions
40
+ # returns an array, each can be one of three things:
41
+ # symbol :flag or :subcommand
42
+ # array [name, description]
43
+ # array [:flagarg, flag_description]
44
+ def summary_descriptions
45
+ send({
46
+ subcommand: :summary_descriptions_subcommand,
47
+ flagarg: :summary_descriptions_flagarg
48
+ }[state.mode])
49
+ end
50
+
51
+ def summary_descriptions_flagarg
52
+ result.current_flags_for_flagargs.map do |flag|
53
+ [:flagarg, flag.description]
54
+ end.compact
55
+ end
56
+
57
+ def summary_descriptions_subcommand
58
+ descriptions = []
59
+ if result.expected_arg
60
+ descriptions << [
61
+ result.expected_arg.title || result.expected_arg.name,
62
+ result.expected_arg.description
63
+ ]
64
+ end
65
+ descriptions << :subcommand if options_subcommand_subs("").any?
66
+ descriptions << :flag if options_subcommand_flags("").any?
67
+ descriptions
68
+ end
69
+
36
70
  private
37
71
 
38
72
  def state
@@ -59,8 +93,8 @@ module Tabry
59
93
  end
60
94
 
61
95
  def options_flagarg(token)
62
- result.sub_stack.map do |sub|
63
- sub.flags[state.current_flag]&.options&.options(token, params)
96
+ result.current_flags_for_flagargs.map do |flag|
97
+ flag.options&.options(token, params)
64
98
  end.compact.flatten.uniq
65
99
  end
66
100
 
@@ -84,13 +118,7 @@ module Tabry
84
118
  end
85
119
 
86
120
  def options_subcommand_args(token)
87
- arg = if current_sub.args.n_passed_in_varargs(state.args.length) > 0
88
- current_sub.args.varargs_arg
89
- else
90
- current_sub.args[state.args.length]
91
- end
92
-
93
- arg&.options&.options(token, params) || []
121
+ result.expected_arg&.options&.options(token, params) || []
94
122
  end
95
123
  end
96
124
  end
@@ -35,7 +35,7 @@ module Tabry
35
35
  rescue Errno::ENOENT # rubocop:disable Lint/SuppressedException
36
36
  end
37
37
 
38
- def save_history(file, max_size = 10000)
38
+ def save_history(file, max_size = 10_000)
39
39
  return unless file
40
40
 
41
41
  history = Readline::HISTORY.each
data/lib/tabry/result.rb CHANGED
@@ -24,7 +24,8 @@ module Tabry
24
24
  def invalid_usage_reason
25
25
  waiting_on_flag_arg? ||
26
26
  wrong_number_of_args? ||
27
- missing_required_flags?
27
+ missing_required_flags? ||
28
+ nil
28
29
  end
29
30
 
30
31
  def waiting_on_flag_arg?
@@ -81,7 +82,7 @@ module Tabry
81
82
  return "missing required flag #{flag.name}"
82
83
  end
83
84
  end
84
- nil
85
+ false
85
86
  end
86
87
 
87
88
  def usage(cmd_name = nil)
@@ -110,5 +111,20 @@ module Tabry
110
111
  end
111
112
  end
112
113
  end
114
+
115
+ def current_flags_for_flagargs
116
+ sub_stack.map do |sub|
117
+ flag = sub.flags[state.current_flag]
118
+ flag if flag&.arg
119
+ end.compact
120
+ end
121
+
122
+ def expected_arg
123
+ if current_sub.args.n_passed_in_varargs(state.args.length) > 0
124
+ current_sub.args.varargs_arg
125
+ else
126
+ current_sub.args[state.args.length]
127
+ end
128
+ end
113
129
  end
114
130
  end
data/lib/tabry/runner.rb CHANGED
@@ -16,11 +16,16 @@ module Tabry
16
16
  config
17
17
  else
18
18
  ConfigLoader.load(name: config)
19
+
19
20
  end
20
21
  end
21
22
 
22
23
  def options(args, last = nil, params = {})
23
- Tabry::OptionsFinder.options(parse(args), last, params)
24
+ options_finder(args, params).options(last)
25
+ end
26
+
27
+ def options_finder(args, params = {})
28
+ Tabry::OptionsFinder.new(parse(args), params)
24
29
  end
25
30
 
26
31
  def parse(args)
@@ -45,8 +45,8 @@ module Tabry
45
45
  File.expand_path("#{__dir__}/../../../")
46
46
  end
47
47
 
48
- def self.esc(s)
49
- Shellwords.escape(s)
48
+ def self.esc(str)
49
+ Shellwords.escape(str)
50
50
  end
51
51
 
52
52
  def self.generate_internal(cmd_name:, import_path:, tabry_bash_executable:, tabry_bash_arg:, uniq_fn_id: nil)
@@ -14,7 +14,7 @@ module Tabry
14
14
 
15
15
  def self.run(cmd_line, comp_point, config: nil)
16
16
  cmd_name, args, last_arg = Tabry::ShellTokenizer.split_with_comppoint(cmd_line, comp_point)
17
- opts = Tabry::Runner.new(config: config || cmd_name).options(args, last_arg, {descriptions: true})
17
+ opts = Tabry::Runner.new(config: config || cmd_name).options(args, last_arg, { descriptions: true })
18
18
 
19
19
  if Tabry::Util.debug?
20
20
  $stderr.puts
@@ -38,12 +38,10 @@ module Tabry
38
38
  def self.format_description(description)
39
39
  if description.nil?
40
40
  ""
41
+ elsif description.length > DESCRIPTION_MAX_LENGTH
42
+ "#{description[0..(DESCRIPTION_MAX_LENGTH - 3)]}..."
41
43
  else
42
- if description.length > DESCRIPTION_MAX_LENGTH
43
- "#{description[0..(DESCRIPTION_MAX_LENGTH - 3)]}..."
44
- else
45
- description
46
- end
44
+ description
47
45
  end
48
46
  end
49
47
  end
@@ -33,7 +33,7 @@ module Tabry
33
33
  cmd_name: cmd_name,
34
34
  import_path: "",
35
35
  tabry_fish_executable: File.expand_path($0),
36
- tabry_fish_arg: "completion",
36
+ tabry_fish_arg: "completion"
37
37
  )
38
38
  end
39
39
 
@@ -41,8 +41,8 @@ module Tabry
41
41
  File.expand_path("#{__dir__}/../../../")
42
42
  end
43
43
 
44
- def self.esc(s)
45
- Shellwords.escape(s)
44
+ def self.esc(str)
45
+ Shellwords.escape(str)
46
46
  end
47
47
 
48
48
  def self.add_uniq_id(str, pattern, uniq_id)
@@ -65,7 +65,7 @@ module Tabry
65
65
 
66
66
  script.gsub! "# TABRY_IMPORT_PATH_REPLACE (DO NOT REMOVE)", "set TABRY_IMPORTS_PATH #{esc import_path}"
67
67
  script.gsub! "# TABRY_EXECUTABLE_REPLACE (DO NOT REMOVE)", "set TABRY_EXECUTABLE #{esc tabry_fish_executable}"
68
- if !tabry_fish_arg.nil?
68
+ unless tabry_fish_arg.nil?
69
69
  script.gsub! "# TABRY_ARG_REPLACE (DO NOT REMOVE)", "set TABRY_ARG #{esc tabry_fish_arg}"
70
70
  end
71
71
 
data/lib/tabry/version.rb CHANGED
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Tabry
2
- VERSION = "0.2.6"
4
+ VERSION = "0.3.0"
3
5
  end
@@ -8,7 +8,7 @@ desc "Build and control vehicles"
8
8
  flag verbose,v "Give more details in output"
9
9
 
10
10
  sub build {
11
- varargs vehicle-types @vehicle-type-arg
11
+ varargs vehicle-types @vehicle-type
12
12
  }
13
13
 
14
14
  sub list-vehicles
@@ -12,7 +12,7 @@ main:
12
12
  - name: vehicle-types
13
13
  options:
14
14
  - type: include
15
- value: vehicle-type-arg
15
+ value: vehicle-type
16
16
  varargs: true
17
17
  - name: list-vehicles
18
18
  - name: move
@@ -76,6 +76,13 @@ describe Tabry::CLI::AllInOne do
76
76
  cli.run(["completion", "bash"])
77
77
  end
78
78
 
79
+ it "creates a #completion__json method which generates tabry JSON" do
80
+ expect_any_instance_of(Kernel).to receive(:puts) do |_, json|
81
+ expect(JSON.parse(json)).to eq(JSON.parse(cli.runner.config.as_json.to_json))
82
+ end
83
+ cli.run(["completion", "json"])
84
+ end
85
+
79
86
  it "creates a #completion method which generates options" do
80
87
  expect(Tabry::Bash::Wrapper).to receive(:run).with("cmd line", "6", config: instance_of(Tabry::Models::Config))
81
88
  cli.run(["completion", "cmd line", "6"])
@@ -31,7 +31,7 @@ describe Tabry::ConfigBuilder do
31
31
  end
32
32
  end
33
33
 
34
- it "defines a 'completion' shortcut with 'completion' and 'completion__bash' subs" do
34
+ it "defines a 'completion' shortcut with 'completion' and completion__bash, __fish, __json subs" do
35
35
  config = described_class.build do
36
36
  completion
37
37
  end
@@ -52,6 +52,10 @@ describe Tabry::ConfigBuilder do
52
52
  }
53
53
  ],
54
54
  "subs" => [
55
+ {
56
+ "description" => "Get flattened tabry JSON config for command (experimental)",
57
+ "name" => "json"
58
+ },
55
59
  {
56
60
  "description" => "Get tab completion for bash or zsh",
57
61
  "name" => "bash"
@@ -22,7 +22,7 @@ describe Tabry::Machine do
22
22
  pending unless expectation
23
23
  result = described_class.run(config, tokens)
24
24
  expectation.each do |key, val|
25
- key = 'subcommand_stack' if key == 'subs'
25
+ key = "subcommand_stack" if key == "subs"
26
26
  res = result.send(key.to_sym)
27
27
  res = res.to_s if res.is_a?(Symbol)
28
28
  expect(res).to eq(val)
@@ -33,6 +33,12 @@ describe Tabry::Models::Config do
33
33
  }
34
34
  end
35
35
 
36
+ describe "#as_json" do
37
+ it "returns the config as a hash" do
38
+ expect(subject.as_json).to eq(config_hash)
39
+ end
40
+ end
41
+
36
42
  describe "#dig_sub_array" do
37
43
  it "returns the array of subcommands leading up to the specified subcommand" do
38
44
  res = subject.dig_sub_array(%w[sub1 sub1.1])
@@ -8,7 +8,7 @@ describe Tabry::Models::DirOption do
8
8
  described_class.new(root: double, raw: { "type" => "dir" })
9
9
  end
10
10
 
11
- # Handled by tabru=bash/tabry-bash.sh/shell, we just return a symbol to
11
+ # Handled by tabry-bash/tabry-bash.sh/shell, we just return a symbol to
12
12
  # communicate to tabry-bash
13
13
  it "returns a array with a symbol" do
14
14
  expect(subject.options("whatever", {})).to eq([:directory])
@@ -8,7 +8,7 @@ describe Tabry::Models::FileOption do
8
8
  described_class.new(root: double, raw: { "type" => "file" })
9
9
  end
10
10
 
11
- # Handled by tabru=bash/tabry-bash.sh/shell, we just return a symbol to
11
+ # Handled by tabry-bash/tabry-bash.sh/shell, we just return a symbol to
12
12
  # communicate to tabry-bash
13
13
  it "returns a array with a symbol" do
14
14
  expect(subject.options("whatever", {})).to eq([:file])
@@ -14,6 +14,6 @@ describe Tabry::Models::ShellOption do
14
14
  expect(subject.options("", {})).to match_array(%w[a a1 b])
15
15
  expect(subject.options("a", {})).to match_array(%w[a a1])
16
16
  expect(subject.options("a1", {})).to match_array(%w[a1])
17
- expect(subject.options("a1 ", {})).to match_array(%w[])
17
+ expect(subject.options("a1 ", {})).to be_empty
18
18
  end
19
19
  end
@@ -4,6 +4,7 @@ require_relative "../../lib/tabry/config_loader"
4
4
  require_relative "../../lib/tabry/options_finder"
5
5
  require_relative "../../lib/tabry/result"
6
6
  require_relative "../../lib/tabry/state"
7
+ require_relative "../../lib/tabry/util"
7
8
 
8
9
  describe Tabry::OptionsFinder do
9
10
  let(:config_fixture) { "#{__dir__}/../fixtures/vehicles.yaml" }
@@ -23,6 +24,10 @@ describe Tabry::OptionsFinder do
23
24
  %w[car bike],
24
25
  subs: %w[move go]
25
26
  ],
27
+ "lists options for varargs" => [
28
+ %w[car bike],
29
+ subs: %w[build],
30
+ ],
26
31
  "lists both possible args and subs if a subcommand can take either" => [
27
32
  %w[x y z subsub],
28
33
  subs: %w[sub-with-sub-or-arg]
@@ -1,6 +1,8 @@
1
- require_relative '../../../lib/tabry/replty/builder'
2
- require_relative '../../../lib/tabry/replty/base'
3
- require_relative '../../../lib/tabry/config_builder'
1
+ # frozen_string_literal: true
2
+
3
+ require_relative "../../../lib/tabry/replty/builder"
4
+ require_relative "../../../lib/tabry/replty/base"
5
+ require_relative "../../../lib/tabry/config_builder"
4
6
 
5
7
  module Tabry
6
8
  module Specs
@@ -21,8 +23,8 @@ module Tabry
21
23
  end
22
24
 
23
25
  describe Tabry::Replty::Builder do
24
- it 'calls the repl method for the subcommand' do
25
- conf = Tabry::ConfigBuilder.build do |c|
26
+ it "calls the repl method for the subcommand" do
27
+ conf = Tabry::ConfigBuilder.build do |_c|
26
28
  sub :foo
27
29
  sub :bar do
28
30
  arg :waz
@@ -28,7 +28,9 @@ describe Tabry::Runner do
28
28
  it "runs OptionsFinder" do
29
29
  res = instance_double(Tabry::Result)
30
30
  expect(subject).to receive(:parse).with(%w[foo bar]).and_return res
31
- expect(Tabry::OptionsFinder).to receive(:options).with(res, "waz", {}).and_return %w[a b c]
31
+ opts_finder = instance_double(Tabry::OptionsFinder)
32
+ expect(Tabry::OptionsFinder).to receive(:new).with(res, {}).and_return opts_finder
33
+ expect(opts_finder).to receive(:options).with("waz").and_return %w[a b c]
32
34
  expect(subject.options(%w[foo bar], "waz")).to eq(%w[a b c])
33
35
  end
34
36
  end
@@ -5,6 +5,7 @@ require_relative "../../../lib/tabry/shells/bash"
5
5
  describe Tabry::Shells::Bash do
6
6
  describe ".generate_self" do
7
7
  before { @backup, $0 = $0, "/bla/waz/abc" }
8
+
8
9
  after { $0 = @backup }
9
10
 
10
11
  it "tells bash to use the currently running command plus 'completion' to get completion options" do
@@ -19,7 +20,7 @@ describe Tabry::Shells::Bash do
19
20
  end
20
21
 
21
22
  it "defaults cmd_name to the basename of the currently running command" do
22
- result = described_class.generate_self(cmd_name: 'wombat')
23
+ result = described_class.generate_self(cmd_name: "wombat")
23
24
  expect(result).to match(
24
25
  %r{^ *TABRY_IMPORTS_PATH='' _tabry_WOMBAT_completions_internal /bla/waz/abc completion$}
25
26
  )
@@ -27,8 +28,8 @@ describe Tabry::Shells::Bash do
27
28
  end
28
29
  end
29
30
 
30
- describe '.generate' do
31
- it 'tells bash to use tabry-bash with a import path to get completion options' do
31
+ describe ".generate" do
32
+ it "tells bash to use tabry-bash with a import path to get completion options" do
32
33
  result = described_class.generate("my-cmd", "/path/to/mycmd.tabry")
33
34
  expect(result).to include("TABRY_IMPORTS_PATH=/path/to/mycmd.tabry _tabry_MY_CMD_completions_internal /")
34
35
  expect(result).to include("complete -F _tabry_MY_CMD_completions my-cmd\n")
data/tabry.gemspec CHANGED
@@ -1,6 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require_relative './lib/tabry/version'
3
+ require_relative "lib/tabry/version"
4
4
 
5
5
  Gem::Specification.new do |s|
6
6
  s.name = "tabry"
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: tabry
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.6
4
+ version: 0.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Evan Battaglia
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2023-11-30 00:00:00.000000000 Z
11
+ date: 2024-07-28 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: pry-byebug
@@ -265,7 +265,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
265
265
  - !ruby/object:Gem::Version
266
266
  version: '0'
267
267
  requirements: []
268
- rubygems_version: 3.3.26
268
+ rubygems_version: 3.4.19
269
269
  signing_key:
270
270
  specification_version: 4
271
271
  summary: Tab completion and CLIs extraordinaire