tabry 0.1.0 → 0.1.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/bin/tabry-bash +3 -0
- data/bin/tabry-help +1 -1
- data/lib/tabry/config_loader.rb +9 -2
- data/lib/tabry/shells/bash.rb +28 -0
- data/sh/bash/README.md +35 -0
- data/sh/bash/tabry_bash.sh +22 -0
- data/sh/{tabry_bash.sh → bash/tabry_bash_core.sh} +6 -16
- data/sh/{tabry_bash_help.sh → bash/tabry_bash_help.sh} +1 -1
- data/spec/tabry/config_loader_spec.rb +9 -3
- data/tabry.gemspec +4 -1
- metadata +6 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: a813a02fd7d1076dfe3f3ee4076fa7d0b4f9fe5c7dae2722f60f7ad0b693fb35
|
4
|
+
data.tar.gz: 0b3631d634da37690deb4e405b856e06f7b12aa8af464a3b4a011d0e68938a57
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: cf85b3d904c1b02b868e205b654328c99ee733c97950c0182a8c5ffc48dcf281443eab28fc870945cad1eb4a34f39af9f2badc1a725506db38d58fd9d417665a
|
7
|
+
data.tar.gz: fdf3ba0343a7ab8b2254a4c9d49996ea18d37854e7fce2c11ccbcf0b456667f636f84d05d6811dde97276f4805372e3669f708a67ca5e4b16201da4ef524f8eb
|
data/bin/tabry-bash
CHANGED
data/bin/tabry-help
CHANGED
@@ -5,7 +5,7 @@ require_relative "../lib/tabry/runner"
|
|
5
5
|
|
6
6
|
# Show usage information stored in a tabry configuration.
|
7
7
|
#
|
8
|
-
# For ease of use, source sh/tabry_bash_help.sh so you can just do
|
8
|
+
# For ease of use, source sh/bash/tabry_bash_help.sh so you can just do
|
9
9
|
# "help mycmd"
|
10
10
|
|
11
11
|
raise "Usage: tabry-help config_name [arg1 [arg2]]..." unless ARGV.length >= 1
|
data/lib/tabry/config_loader.rb
CHANGED
@@ -21,9 +21,16 @@ module Tabry
|
|
21
21
|
def load
|
22
22
|
return load_from_file(name) if name =~ /\.json$/i || name =~ /\.ya?ml$/i
|
23
23
|
|
24
|
-
load_paths.each do |
|
24
|
+
load_paths.each do |path|
|
25
25
|
EXTENSIONS.each do |extension|
|
26
|
-
|
26
|
+
basename = "/#{name}.#{extension}"
|
27
|
+
|
28
|
+
# First check if the path _is_ the file "mycmd.json", "mycmd.yml" we are looking for
|
29
|
+
return load_from_file(path) if path.end_with?(basename) && File.exist?(path)
|
30
|
+
|
31
|
+
# Then look for a file "mycmd.json", "mycmd.yml" etc. in the
|
32
|
+
# directory (assuming it is a directory)
|
33
|
+
filename = "#{path}/#{basename}"
|
27
34
|
return load_from_file(filename) if File.exist?(filename)
|
28
35
|
end
|
29
36
|
end
|
@@ -0,0 +1,28 @@
|
|
1
|
+
module Tabry
|
2
|
+
module Shells
|
3
|
+
module Bash
|
4
|
+
# NOTE! This code uses sh/bash/tabry_bash_core.sh and is described in
|
5
|
+
# sh/bash/README.md; see that README for more info
|
6
|
+
def self.generate(cmd_name, tabry_file_path)
|
7
|
+
capitalized_cmd_name = cmd_name.upcase.gsub(/[^a-zA-Z0-9_]/, '_')
|
8
|
+
tabry_file = Shellwords.escape(File.expand_path(tabry_file_path))
|
9
|
+
path_to_tabry = Shellwords.escape(File.expand_path("#{__dir__}/../../../"))
|
10
|
+
|
11
|
+
core = File.read("#{__dir__}/../../../sh/bash/tabry_bash_core.sh")
|
12
|
+
core.gsub! "_tabry_completions_internal()", "_tabry_#{capitalized_cmd_name}_completions_internal()"
|
13
|
+
|
14
|
+
return <<~END + core
|
15
|
+
# The following Autocomplete is for a Tabry-powered command. It was
|
16
|
+
# generated by the command itself. See the documentation located in
|
17
|
+
# #{path_to_tabry}/sh/bash/README.md
|
18
|
+
_tabry_#{capitalized_cmd_name}_completions() {
|
19
|
+
TABRY_IMPORTS_PATH=#{tabry_file} _tabry_#{capitalized_cmd_name}_completions_internal #{path_to_tabry}/bin/tabry-bash
|
20
|
+
}
|
21
|
+
complete -F _tabry_#{capitalized_cmd_name}_completions #{Shellwords.escape cmd_name}
|
22
|
+
END
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
|
data/sh/bash/README.md
ADDED
@@ -0,0 +1,35 @@
|
|
1
|
+
# Tabry Bash glue
|
2
|
+
|
3
|
+
This directory contains code needed to make Tabry autocomplete work with bash.
|
4
|
+
The code here is basically glue code needed to connect bash's autocomplete
|
5
|
+
framework with Tabry (which does all the work of generating tab completion
|
6
|
+
options). Additionally, `tabry_bash_help.sh` is provided to override bash's
|
7
|
+
help command to provide help to commands that have tabry completion.
|
8
|
+
|
9
|
+
# Quickstart for adding Tab completion
|
10
|
+
* To add Tabry to non-tabry based CLIs, follow the instructions in `tabry_bash.sh`
|
11
|
+
* For Tabry-based CLIs, run "mycmd completion bash" and add the code to your `~/.bash_profile`
|
12
|
+
|
13
|
+
# Tabry Bash autocompletion technical overview
|
14
|
+
The main bash function which calls out to tabry to provide tab completion options is in
|
15
|
+
`tabry_bash_core.sh`. This defines a function called
|
16
|
+
`_tabry_completions_internal`. **If editing the file, it is important you
|
17
|
+
do not rename this function or add lines starting with this function name
|
18
|
+
without understanding the substitution as mentioned below.**
|
19
|
+
|
20
|
+
This file and bash function contained within is used in two ways:
|
21
|
+
* For Ruby CLIs written using tabry, this is renamed to to
|
22
|
+
`_tabry_MYCOMMAND_completions_internal`, and a bit of extra bash code is
|
23
|
+
added on, to make tab completion specific for the program. This is generated
|
24
|
+
for each command when the user runs "mycommand completion bash", which calls
|
25
|
+
`Tabry::Shells::Bash.generate`. A new function for each CLI so different CLIs
|
26
|
+
can use different versions of tabrygq without interfering with each other.
|
27
|
+
The name `_tabry_completions_internal_` is replaced in
|
28
|
+
`lib/tabry/shells/bash.rb` in the `generate` method, so if modifying
|
29
|
+
`tabry_bash_core.sh`, you should if make sure the substitution still works
|
30
|
+
properly.
|
31
|
+
* You can also use Tabry to add tab completion to other non-Tabry CLIs. In this
|
32
|
+
case, the `_tabry_completions_internal_` function is used as-is; it is
|
33
|
+
sourced from `tabry_bash.sh`. See `tabry_bash.sh` for details and
|
34
|
+
instructions on how to use it.
|
35
|
+
|
@@ -0,0 +1,22 @@
|
|
1
|
+
# Use this file to use Tabry tab completion with non-Tabry CLIs. To do this,
|
2
|
+
# source this file in your bash_profile and add lines like
|
3
|
+
# `complete -F _tabry_completions somecli` for each CLI. You will also
|
4
|
+
# need the tabry JSON/YML files in ~/.tabry/ or in a path in your
|
5
|
+
# TABRY_IMPORTS_PATH. For instance, to add tab completion to vaulted and
|
6
|
+
# rapture, you can add this to your ~/.bash_profile:
|
7
|
+
#
|
8
|
+
# source /path/to/tabry/sh/bash/tabry_bash.sh
|
9
|
+
# complete -F _tabry_completions rapture
|
10
|
+
# complete -F _tabry_completions vaulted
|
11
|
+
#
|
12
|
+
# Then be sure to either copy tabry/examples/tabry/vaulted.json and rapture.json to ~/.tabry/,
|
13
|
+
# or set TABRY_IMPORTS_PATH in ~/.bash_profile like so:
|
14
|
+
#
|
15
|
+
# TABRY_IMPORTS_PATH=$TABRY_IMPORTS_PATH:/path/to/tabry/examples/tabry/
|
16
|
+
#
|
17
|
+
|
18
|
+
source "$( dirname "${BASH_SOURCE[0]:-${(%):-%x}}" )"/tabry_bash_core.sh
|
19
|
+
_tabry_completions() {
|
20
|
+
_tabry_completions_internal "$( dirname "${BASH_SOURCE[0]:-${(%):-%x}}" )"/../../bin/tabry-bash
|
21
|
+
}
|
22
|
+
|
@@ -1,19 +1,14 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
# _tabry_completions function is same for any command you use with tabry, you just need
|
5
|
-
# to do `complete -F _tabry_completions mycmd` for your command. This calls the tabry-bash
|
6
|
-
# ruby script. For more info see LANGUAGE_REFERENCE.md
|
7
|
-
|
8
|
-
_tabry_bash="$( dirname "${BASH_SOURCE[0]:-${(%):-%x}}" )"/../bin/tabry-bash
|
9
|
-
|
10
|
-
_tabry_completions()
|
1
|
+
# For more information, or before editing the tabry_bash_core.sh source file,
|
2
|
+
# See sh/bash/README.md and sh/bash/tabry_bash.sh in the tabry gem
|
3
|
+
_tabry_completions_internal()
|
11
4
|
{
|
5
|
+
local tabry_bash="$1"
|
6
|
+
|
12
7
|
[[ -n "$TABRY_DEBUG" ]] && echo && echo -n tabry start bash: && date +%s.%N >&2
|
13
8
|
local saveifs="$IFS"
|
14
9
|
IFS=$'\n'
|
15
10
|
|
16
|
-
local result=`"$
|
11
|
+
local result=`ruby "$tabry_bash" "$COMP_LINE" "$COMP_POINT"`
|
17
12
|
local specials
|
18
13
|
|
19
14
|
if [[ $result == *$'\n'$'\n'* ]]; then
|
@@ -54,8 +49,3 @@ _tabry_completions()
|
|
54
49
|
[[ -n "$TABRY_DEBUG" ]] && echo -n tabry end bash: && date +%s.%N >&2
|
55
50
|
}
|
56
51
|
|
57
|
-
# To use: put a .json/.yml tabry config file in ~/.tabry (e.g. ~/.aws.json)
|
58
|
-
# Then, run this script in your shell startup scripts, plus (e.g.)
|
59
|
-
#
|
60
|
-
# complete -F _tabry_completions aws
|
61
|
-
|
@@ -1,7 +1,7 @@
|
|
1
1
|
# 'help mycommand' -> show tabry help for a tabry-CLI or command you have a
|
2
2
|
# tabry tab completion config for
|
3
3
|
|
4
|
-
_tabry_help="$( dirname "${BASH_SOURCE[0]}" )"
|
4
|
+
_tabry_help="$( dirname "${BASH_SOURCE[0]}" )"/../../bin/tabry-help
|
5
5
|
help() {
|
6
6
|
tabry-help "$@" 2>/dev/null || command help "$@"
|
7
7
|
}
|
@@ -24,22 +24,28 @@ describe Tabry::ConfigLoader do
|
|
24
24
|
describe "use of $TABRY_IMPORTS_PATH" do
|
25
25
|
before { ENV["TABRY_IMPORTS_PATH"] = "#{__dir__}/../fixtures/" }
|
26
26
|
|
27
|
-
it "looks for yaml files in TABRY_IMPORTS_PATH" do
|
27
|
+
it "looks for yaml files in directories in TABRY_IMPORTS_PATH" do
|
28
28
|
config = described_class.load(name: "vehicles")
|
29
29
|
expect(config.main.subs.map(&:name)).to eq(
|
30
30
|
%w[build list-vehicles move sub-with-sub-or-arg sub-with-mandatory-flag]
|
31
31
|
)
|
32
32
|
end
|
33
33
|
|
34
|
-
it "looks for json files in TABRY_IMPORTS_PATH" do
|
34
|
+
it "looks for json files in directories in TABRY_IMPORTS_PATH" do
|
35
35
|
config = described_class.load(name: "basiccli")
|
36
36
|
expect(config.main.subs.map(&:name)).to eq(%w[foo])
|
37
37
|
end
|
38
38
|
|
39
|
-
it "looks for yml files in TABRY_IMPORTS_PATH" do
|
39
|
+
it "looks for yml files in directories in TABRY_IMPORTS_PATH" do
|
40
40
|
config = described_class.load(name: "basiccli2")
|
41
41
|
expect(config.main.subs.map(&:name)).to eq(%w[waz])
|
42
42
|
end
|
43
|
+
|
44
|
+
it "looks for json files in TABRY_IMPORTS_PATH" do
|
45
|
+
ENV["TABRY_IMPORTS_PATH"] = "#{__dir__}/../fixtures/basiccli.json"
|
46
|
+
config = described_class.load(name: "basiccli")
|
47
|
+
expect(config.main.subs.map(&:name)).to eq(%w[foo])
|
48
|
+
end
|
43
49
|
end
|
44
50
|
|
45
51
|
describe "use of $HOME" do
|
data/tabry.gemspec
CHANGED
@@ -6,7 +6,7 @@ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
|
6
6
|
|
7
7
|
Gem::Specification.new do |s|
|
8
8
|
s.name = "tabry"
|
9
|
-
s.version = "0.1.
|
9
|
+
s.version = "0.1.1"
|
10
10
|
s.summary = "Tab completion and CLIs extraordinaire"
|
11
11
|
s.authors = ["Evan Battaglia"]
|
12
12
|
s.email = "battaglia.evan@gmail.com"
|
@@ -18,6 +18,9 @@ Gem::Specification.new do |s|
|
|
18
18
|
s.executables = s.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
19
19
|
s.require_paths = ["lib"]
|
20
20
|
|
21
|
+
# Currently, to get tab completions, we run tabry without bundler. This makes
|
22
|
+
# it much faster, but requires it have no dependencies.
|
23
|
+
|
21
24
|
s.add_development_dependency "pry-byebug", "~> 3.10"
|
22
25
|
s.add_development_dependency "rspec", "~> 3.10"
|
23
26
|
s.add_development_dependency "rubocop", "~> 1.22"
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: tabry
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Evan Battaglia
|
@@ -133,11 +133,14 @@ files:
|
|
133
133
|
- lib/tabry/options_finder.rb
|
134
134
|
- lib/tabry/result.rb
|
135
135
|
- lib/tabry/runner.rb
|
136
|
+
- lib/tabry/shells/bash.rb
|
136
137
|
- lib/tabry/state.rb
|
137
138
|
- lib/tabry/usage_generator.rb
|
138
139
|
- lib/tabry/util.rb
|
139
|
-
- sh/
|
140
|
-
- sh/
|
140
|
+
- sh/bash/README.md
|
141
|
+
- sh/bash/tabry_bash.sh
|
142
|
+
- sh/bash/tabry_bash_core.sh
|
143
|
+
- sh/bash/tabry_bash_help.sh
|
141
144
|
- spec/fixtures/basiccli.json
|
142
145
|
- spec/fixtures/basiccli.tabry
|
143
146
|
- spec/fixtures/basiccli2.tabry
|