tabry 0.2.4 → 0.2.6

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: 87fa1708b1efb9ef81588017419bb6c63455ee786870f882783cf59f22ea462b
4
- data.tar.gz: f0822419f2a36d48148cf7cf0ecdbd195666e2c5fe284d2e8dd6a563976c0842
3
+ metadata.gz: 7733876522770c3037de86e663ddadd59cf1a86b2ddb1bc993934789e5b8d34a
4
+ data.tar.gz: 383673dc7f2ba427e70808fc08484829db28cd5b2c263b21ed1a4971ee2427be
5
5
  SHA512:
6
- metadata.gz: de752dc58cefc4cc1caed94a4f0ae34758fdb40a9973f48ed5471b17fef517b0eecfbfd7e3735179793cce8d16d739d2cb2fe6d833c3f765f5c57e353dac1b7a
7
- data.tar.gz: 3e26e31d951fbc7f076b3c6e5b2c96eccfd1287c5469f84447ec549dc6aca51746dc193cbed36276b2e81dab67ce2bee8204cc0e8bb6b4010a07b284bac75f32
6
+ metadata.gz: e3f75ff33d1b2d3c9e959debc066a672687b906a64a7b414ed57091878cb4ede0ae815d18c563ea619be7ca148bc51c2a571d9cb4075ff4a10ca0c05e64a97cd
7
+ data.tar.gz: 29d82a30fe87411c11c97287bd6af5f1fd279bf2f1a1e44890273c7844d6dd5e0f35916bf4756f2c9fbfbc84f9e6a206862f8d73addbae14cce90666b2b16f89
@@ -19,6 +19,10 @@ module Tabry
19
19
  nil
20
20
  end
21
21
 
22
+ def to_hash
23
+ @hash
24
+ end
25
+
22
26
  def slice(*keys)
23
27
  [keys].flatten.each_with_object({}) do |key, result_hash|
24
28
  result_hash[key] = self[key]
@@ -11,9 +11,9 @@ module Tabry
11
11
 
12
12
  attr_reader(*FIELDS.keys)
13
13
 
14
- # Handled by tabru=bash/tabry-bash.sh/shell, we just return a symbol to
14
+ # Handled by tabry-bash/tabry-bash.sh/shell, we just return a symbol to
15
15
  # communicate to tabry-bash
16
- def options(_token)
16
+ def options(_token, _params)
17
17
  [:directory]
18
18
  end
19
19
 
@@ -11,9 +11,9 @@ module Tabry
11
11
 
12
12
  attr_reader(*FIELDS.keys)
13
13
 
14
- # Handled by tabru=bash/tabry-bash.sh/shell, we just return a symbol to
14
+ # Handled by tabry-bash/tabry-bash.sh/shell, we just return a symbol to
15
15
  # communicate to tabry-bash
16
- def options(_token)
16
+ def options(_token, _params)
17
17
  [:file]
18
18
  end
19
19
 
@@ -16,7 +16,7 @@ module Tabry
16
16
  end
17
17
  end
18
18
 
19
- def options(token, used:, params:)
19
+ def options(token, params, used:)
20
20
  to_a.map do |flag|
21
21
  if token&.start_with?("-") && flag.name_with_dashes.start_with?(token) && !used[flag.name]
22
22
  if params[:descriptions]
@@ -78,7 +78,7 @@ module Tabry
78
78
 
79
79
  result
80
80
  .sub_stack
81
- .map { |sub| sub.flags.options(token, used: state.flags, params: params) }
81
+ .map { |sub| sub.flags.options(token, params, used: state.flags) }
82
82
  .flatten(1)
83
83
  .uniq
84
84
  end
data/lib/tabry/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Tabry
2
- VERSION = "0.2.4"
2
+ VERSION = "0.2.6"
3
3
  end
data/spec/spec_helper.rb CHANGED
@@ -7,4 +7,4 @@ SimpleCov.start do
7
7
  add_filter "spec"
8
8
  track_files "lib/**/*.rb"
9
9
  end
10
- SimpleCov.minimum_coverage(80)
10
+ SimpleCov.minimum_coverage(83)
@@ -55,6 +55,10 @@ describe Tabry::ConfigBuilder do
55
55
  {
56
56
  "description" => "Get tab completion for bash or zsh",
57
57
  "name" => "bash"
58
+ },
59
+ {
60
+ "description" => "Get tab completion for fish",
61
+ "name" => "fish"
58
62
  }
59
63
  ]
60
64
  }
@@ -9,9 +9,9 @@ describe Tabry::Models::ConstOption do
9
9
  end
10
10
 
11
11
  it "filters by prefix" do
12
- expect(subject.options("")).to eq(%w[foobar])
13
- expect(subject.options("f")).to eq(%w[foobar])
14
- expect(subject.options("foo")).to eq(%w[foobar])
15
- expect(subject.options("w")).to eq(%w[])
12
+ expect(subject.options("", {})).to eq(%w[foobar])
13
+ expect(subject.options("f", {})).to eq(%w[foobar])
14
+ expect(subject.options("foo", {})).to eq(%w[foobar])
15
+ expect(subject.options("w", {})).to eq(%w[])
16
16
  end
17
17
  end
@@ -11,6 +11,6 @@ describe Tabry::Models::DirOption do
11
11
  # Handled by tabru=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
- expect(subject.options("whatever")).to eq([:directory])
14
+ expect(subject.options("whatever", {})).to eq([:directory])
15
15
  end
16
16
  end
@@ -11,6 +11,6 @@ describe Tabry::Models::FileOption do
11
11
  # Handled by tabru=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
- expect(subject.options("whatever")).to eq([:file])
14
+ expect(subject.options("whatever", {})).to eq([:file])
15
15
  end
16
16
  end
@@ -39,9 +39,9 @@ describe Tabry::Models::OptionsList do
39
39
  %w[d c b a]
40
40
  ]
41
41
  subject.each_with_index do |opt, i|
42
- expect(opt).to receive(:options).with("some-token").and_return(opts_results[i])
42
+ expect(opt).to receive(:options).with("some-token", {}).and_return(opts_results[i])
43
43
  end
44
- expect(subject.options("some-token")).to match_array(%w[a b c d foo bar waz ok 1])
44
+ expect(subject.options("some-token", {})).to match_array(%w[a b c d foo bar waz ok 1])
45
45
  end
46
46
  end
47
47
  end
@@ -11,9 +11,9 @@ describe Tabry::Models::ShellOption do
11
11
  end
12
12
 
13
13
  it "filters by prefix" do
14
- expect(subject.options("")).to match_array(%w[a a1 b])
15
- expect(subject.options("a")).to match_array(%w[a a1])
16
- expect(subject.options("a1")).to match_array(%w[a1])
17
- expect(subject.options("a1 ")).to match_array(%w[])
14
+ expect(subject.options("", {})).to match_array(%w[a a1 b])
15
+ expect(subject.options("a", {})).to match_array(%w[a a1])
16
+ expect(subject.options("a1", {})).to match_array(%w[a1])
17
+ expect(subject.options("a1 ", {})).to match_array(%w[])
18
18
  end
19
19
  end
@@ -85,7 +85,7 @@ describe Tabry::OptionsFinder do
85
85
  hash[:subcommand_stack] = hash.delete(:subs) || []
86
86
  defaults = { mode: :subcommand, args: [], flags: {}, current_flag: nil, dashdash: nil }
87
87
  result = Tabry::Result.new(config, Tabry::State.new(defaults.merge(hash)))
88
- expect(described_class.options(result, token)).to match_array expected_options
88
+ expect(described_class.options(result, token, {})).to match_array expected_options
89
89
  end
90
90
  end
91
91
 
@@ -115,12 +115,12 @@ describe Tabry::OptionsFinder do
115
115
  )
116
116
  end
117
117
 
118
- described_class.options(result, "abcd")
118
+ described_class.options(result, "abcd", {})
119
119
  end
120
120
 
121
121
  it "sets TABRY_AUTOCOMPLETE_STATE back to what it was before" do
122
122
  ENV["TABRY_AUTOCOMPLETE_STATE"] = "foobar1234"
123
- described_class.options(result, "foo")
123
+ described_class.options(result, "foo", {})
124
124
  expect(ENV.fetch("TABRY_AUTOCOMPLETE_STATE", nil)).to eq("foobar1234")
125
125
  end
126
126
  end
@@ -0,0 +1,39 @@
1
+ require_relative '../../../lib/tabry/replty/builder'
2
+ require_relative '../../../lib/tabry/replty/base'
3
+ require_relative '../../../lib/tabry/config_builder'
4
+
5
+ module Tabry
6
+ module Specs
7
+ class TestRepl < Tabry::Replty::Base
8
+ def log
9
+ @log ||= []
10
+ end
11
+
12
+ def foo
13
+ log << [:foo]
14
+ end
15
+
16
+ def bar
17
+ log << [:bar, args.waz, flags.ok]
18
+ end
19
+ end
20
+ end
21
+ end
22
+
23
+ describe Tabry::Replty::Builder do
24
+ it 'calls the repl method for the subcommand' do
25
+ conf = Tabry::ConfigBuilder.build do |c|
26
+ sub :foo
27
+ sub :bar do
28
+ arg :waz
29
+ flag :ok
30
+ end
31
+ end
32
+
33
+ repl = Tabry::Specs::TestRepl.new
34
+ builder = Tabry::Replty::Builder.new(conf, repl)
35
+ expect(builder).to receive(:readline).and_return("bar waz --ok")
36
+ expect(builder).to receive(:readline).and_return(nil)
37
+ builder.run
38
+ end
39
+ end
@@ -28,7 +28,7 @@ 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
+ expect(Tabry::OptionsFinder).to receive(:options).with(res, "waz", {}).and_return %w[a b c]
32
32
  expect(subject.options(%w[foo bar], "waz")).to eq(%w[a b c])
33
33
  end
34
34
  end
@@ -23,6 +23,11 @@ describe Tabry::ShellTokenizer do
23
23
  )
24
24
  end
25
25
 
26
+ it "uses comppoint to correctly figures out whether we are still on the last token" do
27
+ expect(described_class.split_with_comppoint("jir add ", 7)).to eq(["jir", [], "add"])
28
+ expect(described_class.split_with_comppoint("jir add ", 8)).to eq(["jir", ["add"], ""])
29
+ end
30
+
26
31
  it "supports tokens with argument (tab on command), yielding the last arg" do
27
32
  expect(described_class.split_with_comppoint("abc", 2)).to eq([nil, [], "abc"])
28
33
  end
@@ -30,13 +30,13 @@ describe Tabry::Shells::Bash do
30
30
  describe '.generate' do
31
31
  it 'tells bash to use tabry-bash with a import path to get completion options' do
32
32
  result = described_class.generate("my-cmd", "/path/to/mycmd.tabry")
33
- expect(result).to include("TABRY_IMPORTS_PATH=/path/to/mycmd.tabry _tabry_MY_CMD_completions_internal /home/evan/dev/tabry/bin/tabry-bash \n")
33
+ expect(result).to include("TABRY_IMPORTS_PATH=/path/to/mycmd.tabry _tabry_MY_CMD_completions_internal /")
34
34
  expect(result).to include("complete -F _tabry_MY_CMD_completions my-cmd\n")
35
35
  end
36
36
 
37
37
  it "takes a uniq_fn_id parameter to override the default function names" do
38
38
  result = described_class.generate("my-cmd", "/path/to/mycmd.tabry", uniq_fn_id: "my cmd tabryv0.2.0")
39
- expect(result).to include("TABRY_IMPORTS_PATH=/path/to/mycmd.tabry _tabry_MY_CMD_TABRYV0_2_0_completions_internal /home/evan/dev/tabry/bin/tabry-bash \n")
39
+ expect(result).to include("TABRY_IMPORTS_PATH=/path/to/mycmd.tabry _tabry_MY_CMD_TABRYV0_2_0_completions_internal /")
40
40
  expect(result).to include("complete -F _tabry_MY_CMD_TABRYV0_2_0_completions my-cmd\n")
41
41
  expect(result).to include("_tabry_MY_CMD_TABRYV0_2_0_completions_internal()")
42
42
  end
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.4
4
+ version: 0.2.6
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-07-19 00:00:00.000000000 Z
11
+ date: 2023-11-30 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: pry-byebug
@@ -203,6 +203,7 @@ files:
203
203
  - spec/tabry/models/shell_option_spec.rb
204
204
  - spec/tabry/models/subs_list_spec.rb
205
205
  - spec/tabry/options_finder_spec.rb
206
+ - spec/tabry/replty/builder_spec.rb
206
207
  - spec/tabry/result_spec.rb
207
208
  - spec/tabry/runner_spec.rb
208
209
  - spec/tabry/shell_tokenizer_spec.rb