thor-zsh_completion 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 2d2b258587a459e70ec955724fb631aafc73786f
4
+ data.tar.gz: 24905d7c013630ac13c9bea4e6a29cfb3af9f2b3
5
+ SHA512:
6
+ metadata.gz: 1b30db3b9e7649a2f3253aa6f54d061d40db7b5381829ceae9b923d6435ff68653f3c7d582a677dd304e73c84e0cd5b091f7028f82b7507c79548f6cde369877
7
+ data.tar.gz: b69f1767db423e6f957573fe30f866adf44d7e0bd17b70a9cb3b06f77cdc5136a23feea4749ab5db07d3e481fcb52bc97070449fc59ff99b387da29e7f0fd4ed
data/.gitignore ADDED
@@ -0,0 +1,9 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --format documentation
2
+ --color
data/.travis.yml ADDED
@@ -0,0 +1,4 @@
1
+ language: ruby
2
+ rvm:
3
+ - 2.2.3
4
+ before_install: gem install bundler -v 1.10.6
@@ -0,0 +1,13 @@
1
+ # Contributor Code of Conduct
2
+
3
+ As contributors and maintainers of this project, we pledge to respect all people who contribute through reporting issues, posting feature requests, updating documentation, submitting pull requests or patches, and other activities.
4
+
5
+ We are committed to making participation in this project a harassment-free experience for everyone, regardless of level of experience, gender, gender identity and expression, sexual orientation, disability, personal appearance, body size, race, ethnicity, age, or religion.
6
+
7
+ Examples of unacceptable behavior by participants include the use of sexual language or imagery, derogatory comments or personal attacks, trolling, public or private harassment, insults, or other unprofessional conduct.
8
+
9
+ Project maintainers have the right and responsibility to remove, edit, or reject comments, commits, code, wiki edits, issues, and other contributions that are not aligned to this Code of Conduct. Project maintainers who do not follow the Code of Conduct may be removed from the project team.
10
+
11
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be reported by opening an issue or contacting one or more of the project maintainers.
12
+
13
+ This Code of Conduct is adapted from the [Contributor Covenant](http://contributor-covenant.org), version 1.0.0, available at [http://contributor-covenant.org/version/1/0/0/](http://contributor-covenant.org/version/1/0/0/)
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in thor-zsh_completion.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2015 labocho
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,81 @@
1
+ # Thor::ZshCompletion
2
+
3
+ Create zsh completion script for [Thor](http://whatisthor.com/) subclass.
4
+
5
+
6
+ ## Feature
7
+
8
+ This creates completion script that completes...
9
+
10
+ - Subcommands (includes nested subcommands such as `knife solo cook ...`)
11
+ - Options for subcommands.
12
+
13
+ But...
14
+
15
+ - Does not support arguments for subcommand, all arguments are completed as file.
16
+ - Does not support arguments for options, all arguments are completed as file.
17
+
18
+
19
+ ## Installation
20
+
21
+ Add this line to your application's Gemfile:
22
+
23
+ gem 'thor-zsh_completion'
24
+
25
+
26
+ And then execute:
27
+
28
+ $ bundle
29
+
30
+ Or install it yourself as:
31
+
32
+ $ gem install thor-zsh_completion
33
+
34
+
35
+ ## Usage
36
+
37
+ To generate completion script:
38
+
39
+ require "thor"
40
+ require "thor/zsh_completion"
41
+
42
+ class YourCommand < Thor
43
+ # ...
44
+ end
45
+
46
+ puts Thor::ZshCompletion::Generator.new(YourCommand, "yourcommand").generate
47
+
48
+ Or include `Thor::ZshCompletion::Command` to add subcommand `zsh-completion`
49
+
50
+ require "thor"
51
+ require "thor/zsh_completion"
52
+
53
+ class YourCommand < Thor
54
+ include ZshCompletion::Command
55
+ # ...
56
+ end
57
+
58
+ YourCommand.start(ARGV)
59
+
60
+ and execute below.
61
+
62
+ $ yourcommand zsh-completion [--name=yourcommand] > path/to/fpath/_yourcommand
63
+
64
+
65
+ ## Development
66
+
67
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
68
+
69
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
70
+
71
+
72
+ ## Contributing
73
+
74
+ Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/thor-zsh_completion. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](contributor-covenant.org) code of conduct.
75
+
76
+
77
+
78
+ ## License
79
+
80
+ The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
81
+
data/Rakefile ADDED
@@ -0,0 +1,6 @@
1
+ require "bundler/gem_tasks"
2
+ require "rspec/core/rake_task"
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task :default => :spec
data/bin/console ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "thor/zsh_completion"
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require "irb"
14
+ IRB.start
data/bin/setup ADDED
@@ -0,0 +1,7 @@
1
+ #!/bin/bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+
5
+ bundle install
6
+
7
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,16 @@
1
+ class Thor
2
+ module ZshCompletion
3
+ module Command
4
+ def self.included(klass)
5
+ klass.class_eval do
6
+ desc "zsh-completion", "Print zsh completion script"
7
+ option :name, aliases: [:n]
8
+ def zsh_completion
9
+ name = options.name || File.basename($0)
10
+ puts ZshCompletion::Generator.new(self.class, name).generate
11
+ end
12
+ end
13
+ end
14
+ end
15
+ end
16
+ end
@@ -0,0 +1,96 @@
1
+ class Thor
2
+ module ZshCompletion
3
+ class Generator
4
+ SUBCOMMAND_FUNCTION_TEMPLATE = ERB.new(File.read("#{__dir__}/template/subcommand_function.erb"), nil, "-")
5
+ attr_reader :thor, :name
6
+
7
+ def initialize(thor, name)
8
+ @thor = thor
9
+ @name = name
10
+ end
11
+
12
+ def generate
13
+ # Format command information like below:
14
+ #
15
+ # { name: "__iterm",
16
+ # options: [],
17
+ # subcommands: [
18
+ # { name: "list-sessions",
19
+ # description: "List name of all sessions in current terminal",
20
+ # options: [],
21
+ # subcommands: [],
22
+ # },
23
+ # { name: "new-session",
24
+ # description: "Create new session in current terminal",
25
+ # options: [
26
+ # { names: ["--name", "-n"],
27
+ # description: nil,
28
+ # },
29
+ # ],
30
+ # subcommands: [],
31
+ # },
32
+ # { name: "sessions",
33
+ # description: "Manage sessions by .iterm-sessions",
34
+ # options: [],
35
+ # subcommands: [
36
+ # { name: "start",
37
+ # description: "Start all sessions if it's not started",
38
+ # options: [],
39
+ # subcommands: [],
40
+ # }
41
+ # ]
42
+ # }
43
+ # ]
44
+ # }
45
+
46
+ main = {
47
+ name: "__#{name}",
48
+ description: nil,
49
+ options: [],
50
+ subcommands: subcommand_metadata(thor)
51
+ }
52
+
53
+ erb = File.read("#{__dir__}/template/main.erb")
54
+ ERB.new(erb, nil, "-").result(binding)
55
+ end
56
+
57
+ private
58
+ def render_subcommand_function(subcommand, prefix: [])
59
+ source = []
60
+
61
+ prefix = (prefix + [subcommand[:name]])
62
+ function_name = prefix.join("_")
63
+ depth = prefix.size + 1
64
+
65
+ source << SUBCOMMAND_FUNCTION_TEMPLATE.result(binding)
66
+ subcommand[:subcommands].each do |subcommand|
67
+ source << render_subcommand_function(subcommand, prefix: prefix)
68
+ end
69
+ source.join("\n").strip + "\n"
70
+ end
71
+
72
+ def subcommand_metadata(thor)
73
+ thor.tasks.map do |(name, command)|
74
+ if subcommand_class = thor.subcommand_classes[name]
75
+ subcommands = subcommand_metadata(subcommand_class)
76
+ else
77
+ subcommands = []
78
+ end
79
+ { name: command.name.gsub("_", "-"),
80
+ usage: command.usage,
81
+ description: command.description,
82
+ options: thor.class_options.map{|_, o| option_metadata(o) } +
83
+ command.options.map{|(_, o)| option_metadata(o) },
84
+ subcommands: subcommands
85
+ }
86
+ end
87
+ end
88
+
89
+ def option_metadata(option)
90
+ { names: ["--#{option.name}"] + option.aliases.map{|a| "-#{a}" },
91
+ description: option.description,
92
+ }
93
+ end
94
+ end
95
+ end
96
+ end
@@ -0,0 +1,11 @@
1
+ #compdef <%= name %>
2
+
3
+ local state
4
+
5
+ _<%= name %>() {
6
+ __<%= name %>
7
+ }
8
+
9
+ <%= render_subcommand_function(main) %>
10
+
11
+ compdef _<%= name %> <%= name %>
@@ -0,0 +1,55 @@
1
+ <%- if subcommand[:subcommands].any? %>
2
+ <%= function_name %>() {
3
+ readonly local DEPTH=<%= depth %>
4
+
5
+ case $CURRENT in
6
+ $DEPTH)
7
+ _arguments \
8
+ <%- subcommand[:options].each do |option| -%>
9
+ {<%= option[:names].join(",") %>}<%= option[:description].gsub(/'/, "''") if option[:description] %> \
10
+ <%- end -%>
11
+ '*: :->subcommands'
12
+
13
+ case $state in
14
+ subcommands)
15
+ _values \
16
+ 'subcommand' \
17
+ <%- subcommand[:subcommands].each do |subcommand| -%>
18
+ '<%= subcommand[:name] %>[<%= subcommand[:description].gsub(/'/, "''") %>]' \
19
+ <%- end -%>
20
+ ;
21
+ ;;
22
+ esac
23
+ ;;
24
+ *)
25
+ case $words[$DEPTH] in
26
+ <%- subcommand[:subcommands].each do |subcommand| -%>
27
+ <%= subcommand[:name] %>)
28
+ <%= function_name %>_<%= subcommand[:name] %>
29
+ ;;
30
+ <%- end -%>
31
+ *)
32
+ # if does not match any subcommand
33
+ # complete rest arguments
34
+ _files
35
+ ;;
36
+ esac
37
+ ;;
38
+ esac
39
+ }
40
+ <%- else %>
41
+ <%= function_name %>() {
42
+ _arguments \
43
+ <%- subcommand[:options].each do |option| -%>
44
+ {<%= option[:names].join(",") %>}<%= option[:description].gsub(/'/, "''") if option[:description] %> \
45
+ <%- end -%>
46
+ '*: :->rest'
47
+
48
+ case $state in
49
+ rest)
50
+ # complete rest arguments
51
+ _files
52
+ ;;
53
+ esac
54
+ }
55
+ <%- end %>
@@ -0,0 +1,5 @@
1
+ class Thor
2
+ module ZshCompletion
3
+ VERSION = "0.1.0"
4
+ end
5
+ end
@@ -0,0 +1,11 @@
1
+ require "thor"
2
+ require "thor/zsh_completion/version"
3
+ require "erb"
4
+
5
+ class Thor
6
+ module ZshCompletion
7
+ end
8
+ end
9
+
10
+ require "thor/zsh_completion/command"
11
+ require "thor/zsh_completion/generator"
@@ -0,0 +1,25 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'thor/zsh_completion/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "thor-zsh_completion"
8
+ spec.version = Thor::ZshCompletion::VERSION
9
+ spec.authors = ["labocho"]
10
+ spec.email = ["labocho@penguinlab.jp"]
11
+
12
+ spec.summary = %q{Create zsh completion script for Thor subclass}
13
+ spec.description = %q{Create zsh completion script for Thor subclass}
14
+ spec.homepage = "https://github.com/labocho/thor-zsh_completion"
15
+ spec.license = "MIT"
16
+
17
+ spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
18
+ spec.bindir = "exe"
19
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
20
+ spec.require_paths = ["lib"]
21
+
22
+ spec.add_development_dependency "bundler", "~> 1.10"
23
+ spec.add_development_dependency "rake", "~> 10.0"
24
+ spec.add_development_dependency "rspec"
25
+ end
metadata ADDED
@@ -0,0 +1,103 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: thor-zsh_completion
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - labocho
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2015-12-17 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.10'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.10'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '10.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '10.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rspec
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ description: Create zsh completion script for Thor subclass
56
+ email:
57
+ - labocho@penguinlab.jp
58
+ executables: []
59
+ extensions: []
60
+ extra_rdoc_files: []
61
+ files:
62
+ - ".gitignore"
63
+ - ".rspec"
64
+ - ".travis.yml"
65
+ - CODE_OF_CONDUCT.md
66
+ - Gemfile
67
+ - LICENSE.txt
68
+ - README.md
69
+ - Rakefile
70
+ - bin/console
71
+ - bin/setup
72
+ - lib/thor/zsh_completion.rb
73
+ - lib/thor/zsh_completion/command.rb
74
+ - lib/thor/zsh_completion/generator.rb
75
+ - lib/thor/zsh_completion/template/main.erb
76
+ - lib/thor/zsh_completion/template/subcommand_function.erb
77
+ - lib/thor/zsh_completion/version.rb
78
+ - thor-zsh_completion.gemspec
79
+ homepage: https://github.com/labocho/thor-zsh_completion
80
+ licenses:
81
+ - MIT
82
+ metadata: {}
83
+ post_install_message:
84
+ rdoc_options: []
85
+ require_paths:
86
+ - lib
87
+ required_ruby_version: !ruby/object:Gem::Requirement
88
+ requirements:
89
+ - - ">="
90
+ - !ruby/object:Gem::Version
91
+ version: '0'
92
+ required_rubygems_version: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - ">="
95
+ - !ruby/object:Gem::Version
96
+ version: '0'
97
+ requirements: []
98
+ rubyforge_project:
99
+ rubygems_version: 2.4.5.1
100
+ signing_key:
101
+ specification_version: 4
102
+ summary: Create zsh completion script for Thor subclass
103
+ test_files: []