thor-zsh_completion 0.1.1 → 0.1.7

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 80edce6f394ea4b9fc61c8ec1d3de8120cc6fc67dd0ea4a3f696802582bf368d
4
+ data.tar.gz: e57bca556d1cb99cf7ab21ab359777a244f2bf92fe106f5668191dd5a2a20b2a
5
+ SHA512:
6
+ metadata.gz: d12f3e04253be27957e5cb0aad094988e95bd93fc7d9a4bd82179fd769b61e7ef8e53cbd454c9b8e5bafd4c75485ae58e322654b0ba7251969019f9eaea33747
7
+ data.tar.gz: 0e7464b50012941279344e9ab849a3f1cc6cff8d1a9752b1ee5d5ab8f93d9b6f2d65bcb26e1101fcf6218c536007fc70b01443208391346fb46200543a2c076e
@@ -0,0 +1,127 @@
1
+ AllCops:
2
+ Exclude:
3
+ - bin/*
4
+ - node_modules/**/*
5
+ NewCops: enable
6
+
7
+ Layout/CaseIndentation:
8
+ EnforcedStyle: end
9
+
10
+ Layout/EndAlignment:
11
+ EnforcedStyleAlignWith: variable
12
+
13
+ Layout/LineLength:
14
+ Enabled: false
15
+
16
+ Layout/EmptyLinesAroundAccessModifier:
17
+ EnforcedStyle: only_before
18
+
19
+ Layout/SpaceInLambdaLiteral:
20
+ EnforcedStyle: require_space
21
+
22
+ Layout/SpaceInsideBlockBraces:
23
+ SpaceBeforeBlockParameters: false
24
+
25
+ Layout/SpaceInsideHashLiteralBraces:
26
+ EnforcedStyle: no_space
27
+
28
+ Metrics/AbcSize:
29
+ Enabled: false
30
+
31
+ Metrics/BlockLength:
32
+ Enabled: false
33
+
34
+ Metrics/ClassLength:
35
+ Enabled: false
36
+
37
+ Metrics/CyclomaticComplexity:
38
+ Enabled: false
39
+
40
+ Metrics/MethodLength:
41
+ Enabled: false
42
+
43
+ Metrics/ModuleLength:
44
+ Enabled: false
45
+
46
+ Metrics/PerceivedComplexity:
47
+ Enabled: false
48
+
49
+ Naming/HeredocDelimiterNaming:
50
+ Enabled: false
51
+
52
+ Naming/MethodParameterName:
53
+ Enabled: false
54
+
55
+ Naming/PredicateName:
56
+ Enabled: false
57
+
58
+ Style/Alias:
59
+ EnforcedStyle: prefer_alias_method
60
+
61
+ Style/AsciiComments:
62
+ Enabled: false
63
+
64
+ Style/BlockDelimiters:
65
+ Enabled: false
66
+
67
+ Style/Documentation:
68
+ Enabled: false
69
+
70
+ Style/EmptyCaseCondition:
71
+ Enabled: false
72
+
73
+ Style/EmptyMethod:
74
+ EnforcedStyle: expanded
75
+
76
+ Style/FrozenStringLiteralComment:
77
+ Enabled: false
78
+
79
+ Style/HashSyntax:
80
+ Exclude:
81
+ - Rakefile
82
+ - "**/*.rake"
83
+
84
+ Style/Lambda:
85
+ EnforcedStyle: literal
86
+
87
+ Style/IfUnlessModifier:
88
+ Enabled: false
89
+
90
+ Style/MultilineBlockChain:
91
+ Enabled: false
92
+
93
+ Style/NumericLiterals:
94
+ Enabled: false
95
+
96
+ Style/NumericPredicate:
97
+ Enabled: false
98
+
99
+ Style/PercentLiteralDelimiters:
100
+ PreferredDelimiters:
101
+ '%i': '()'
102
+ '%w': '()'
103
+ '%r': '()'
104
+
105
+ Style/SpecialGlobalVars:
106
+ Enabled: false
107
+
108
+ Style/StringLiterals:
109
+ EnforcedStyle: double_quotes
110
+
111
+ Style/StringLiteralsInInterpolation:
112
+ EnforcedStyle: double_quotes
113
+
114
+ Style/SymbolArray:
115
+ Enabled: false
116
+
117
+ Style/TrailingCommaInArguments:
118
+ EnforcedStyleForMultiline: consistent_comma
119
+
120
+ Style/TrailingCommaInArrayLiteral:
121
+ EnforcedStyleForMultiline: consistent_comma
122
+
123
+ Style/TrailingCommaInHashLiteral:
124
+ EnforcedStyleForMultiline: consistent_comma
125
+
126
+ Style/ZeroLengthPredicate:
127
+ Enabled: false
@@ -0,0 +1,40 @@
1
+ ### 0.1.7
2
+
3
+ Misc
4
+
5
+ - fix the generation of zsh completion scripts to prevent all [ShellCheck](https://www.shellcheck.net/) warnings
6
+
7
+ ### 0.1.6
8
+
9
+ Misc
10
+
11
+ - fix the generation of zsh completion scripts to prevent [ShellCheck](https://www.shellcheck.net/) warnings (@joehorsnell)
12
+
13
+ ### 0.1.5
14
+
15
+ Bugfixes
16
+
17
+ - remove unnecessary `local state` in generated script. (reported by @aoyama-val)
18
+
19
+ ### 0.1.4
20
+
21
+ Bugfixes
22
+
23
+ - support `Thor.map`. (by @Zhomart)
24
+
25
+ ### 0.1.3
26
+
27
+ Bugfixes
28
+
29
+ - fix invalid script generation bug for option description. (by @tbpgr)
30
+ - fix invalid script generation bug for not aliased option.
31
+
32
+ ### 0.1.1
33
+
34
+ Features
35
+
36
+ - support ruby 1.9.3.
37
+
38
+ ### 0.1.0
39
+
40
+ - initial release.
data/Gemfile CHANGED
@@ -1,4 +1,9 @@
1
- source 'https://rubygems.org'
1
+ source "https://rubygems.org"
2
2
 
3
3
  # Specify your gem's dependencies in thor-zsh_completion.gemspec
4
4
  gemspec
5
+
6
+ gem "bundler", "~> 2.1"
7
+ gem "rake", "~> 13.0"
8
+ gem "rspec", "~> 3.9"
9
+ gem "rubocop", "~> 0.86"
data/README.md CHANGED
@@ -69,6 +69,11 @@ After checking out the repo, run `bin/setup` to install dependencies. Then, run
69
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
70
 
71
71
 
72
+ ### Testing completion script
73
+
74
+ source spec/thor/zsh_completion/generator_spec.zsh
75
+ generator_spec [TAB]
76
+
72
77
  ## Contributing
73
78
 
74
79
  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.
@@ -0,0 +1,29 @@
1
+ #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
3
+
4
+ #
5
+ # This file was generated by Bundler.
6
+ #
7
+ # The application 'rspec' is installed as part of a gem, and
8
+ # this file is here to facilitate running it.
9
+ #
10
+
11
+ require "pathname"
12
+ ENV["BUNDLE_GEMFILE"] ||= File.expand_path("../../Gemfile",
13
+ Pathname.new(__FILE__).realpath)
14
+
15
+ bundle_binstub = File.expand_path("../bundle", __FILE__)
16
+
17
+ if File.file?(bundle_binstub)
18
+ if File.read(bundle_binstub, 300) =~ /This file was generated by Bundler/
19
+ load(bundle_binstub)
20
+ else
21
+ abort("Your `bin/bundle` was not generated by Bundler, so this binstub cannot run.
22
+ Replace `bin/bundle` by running `bundle binstubs bundler --force`, then run this command again.")
23
+ end
24
+ end
25
+
26
+ require "rubygems"
27
+ require "bundler/setup"
28
+
29
+ load Gem.bin_path("rspec-core", "rspec")
@@ -0,0 +1,29 @@
1
+ #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
3
+
4
+ #
5
+ # This file was generated by Bundler.
6
+ #
7
+ # The application 'rubocop' is installed as part of a gem, and
8
+ # this file is here to facilitate running it.
9
+ #
10
+
11
+ require "pathname"
12
+ ENV["BUNDLE_GEMFILE"] ||= File.expand_path("../../Gemfile",
13
+ Pathname.new(__FILE__).realpath)
14
+
15
+ bundle_binstub = File.expand_path("../bundle", __FILE__)
16
+
17
+ if File.file?(bundle_binstub)
18
+ if File.read(bundle_binstub, 300) =~ /This file was generated by Bundler/
19
+ load(bundle_binstub)
20
+ else
21
+ abort("Your `bin/bundle` was not generated by Bundler, so this binstub cannot run.
22
+ Replace `bin/bundle` by running `bundle binstubs bundler --force`, then run this command again.")
23
+ end
24
+ end
25
+
26
+ require "rubygems"
27
+ require "bundler/setup"
28
+
29
+ load Gem.bin_path("rubocop", "rubocop")
@@ -47,7 +47,7 @@ class Thor
47
47
  name: "__#{name}",
48
48
  description: nil,
49
49
  options: [],
50
- subcommands: subcommand_metadata(thor)
50
+ subcommands: subcommand_metadata(thor),
51
51
  }
52
52
 
53
53
  erb = File.read("#{File.dirname(__FILE__)}/template/main.erb")
@@ -65,33 +65,63 @@ class Thor
65
65
  depth = prefix.size + 1
66
66
 
67
67
  source << SUBCOMMAND_FUNCTION_TEMPLATE.result(binding)
68
- subcommand[:subcommands].each do |subcommand|
69
- source << render_subcommand_function(subcommand, prefix: prefix)
68
+
69
+ subcommand[:subcommands].each do |nested|
70
+ source << render_subcommand_function(nested, prefix: prefix)
70
71
  end
71
72
  source.join("\n").strip + "\n"
72
73
  end
73
74
 
74
75
  def subcommand_metadata(thor)
75
- thor.tasks.map do |(name, command)|
76
- if subcommand_class = thor.subcommand_classes[name]
77
- subcommands = subcommand_metadata(subcommand_class)
78
- else
79
- subcommands = []
80
- end
81
- { name: command.name.gsub("_", "-"),
82
- usage: command.usage,
83
- description: command.description,
84
- options: thor.class_options.map{|_, o| option_metadata(o) } +
85
- command.options.map{|(_, o)| option_metadata(o) },
86
- subcommands: subcommands
87
- }
76
+ result = []
77
+ thor.tasks.each do |(name, command)|
78
+ aliases = thor.map.select {|_, original_name|
79
+ name == original_name
80
+ }.map(&:first)
81
+ result << generate_command_information(thor, name, command, aliases)
82
+ end
83
+ result
84
+ end
85
+
86
+ def generate_command_information(thor, name, command, aliases)
87
+ subcommands = if (subcommand_class = thor.subcommand_classes[name])
88
+ subcommand_metadata(subcommand_class)
89
+ else
90
+ []
88
91
  end
92
+ {name: hyphenate(name),
93
+ aliases: aliases.map {|a| hyphenate(a) },
94
+ usage: command.usage,
95
+ description: command.description,
96
+ options: thor.class_options.map {|_, o| option_metadata(o) } +
97
+ command.options.map {|(_, o)| option_metadata(o) },
98
+ subcommands: subcommands,}
89
99
  end
90
100
 
91
101
  def option_metadata(option)
92
- { names: ["--#{option.name}"] + option.aliases.map{|a| "-#{a}" },
93
- description: option.description,
94
- }
102
+ {names: ["--#{option.name}"] + option.aliases.map {|a| "-#{a}" },
103
+ description: option.description,}
104
+ end
105
+
106
+ def quote(s)
107
+ escaped = s.gsub(/'/, "''")
108
+ %('#{escaped}')
109
+ end
110
+
111
+ def bracket(s)
112
+ %([#{s}])
113
+ end
114
+
115
+ def escape_option_names(names)
116
+ if names.size == 1
117
+ names.first
118
+ else
119
+ "{" + names.join(",") + "}"
120
+ end
121
+ end
122
+
123
+ def hyphenate(s)
124
+ s.gsub("_", "-")
95
125
  end
96
126
  end
97
127
  end
@@ -1,6 +1,6 @@
1
1
  #compdef <%= name %>
2
-
3
- local state
2
+ # shellcheck disable=SC2034
3
+ # https://github.com/koalaman/shellcheck/wiki/SC2034
4
4
 
5
5
  _<%= name %>() {
6
6
  __<%= name %>
@@ -3,30 +3,38 @@
3
3
  readonly local DEPTH=<%= depth %>
4
4
 
5
5
  case $CURRENT in
6
- $DEPTH)
6
+ "$DEPTH")
7
7
  _arguments \
8
8
  <%- subcommand[:options].each do |option| -%>
9
- {<%= option[:names].join(",") %>}<%= option[:description].gsub(/'/, "''") if option[:description] %> \
9
+ <%= escape_option_names(option[:names]) %><%= quote(bracket(option[:description])) if option[:description] %> \
10
10
  <%- end -%>
11
11
  '*: :->subcommands'
12
12
 
13
- case $state in
13
+ case ${state:?} in
14
14
  subcommands)
15
15
  _values \
16
16
  'subcommand' \
17
17
  <%- subcommand[:subcommands].each do |subcommand| -%>
18
- '<%= subcommand[:name] %>[<%= subcommand[:description].gsub(/'/, "''") %>]' \
18
+ <%= quote(subcommand[:name] + bracket(subcommand[:description])) %> \
19
+ <%- subcommand[:aliases].each do |_alias| -%>
20
+ <%= quote(_alias + bracket(subcommand[:description])) %> \
21
+ <%- end -%>
19
22
  <%- end -%>
20
23
  ;
21
24
  ;;
22
25
  esac
23
26
  ;;
24
27
  *)
25
- case $words[$DEPTH] in
28
+ case ${words[$DEPTH]:?} in
26
29
  <%- subcommand[:subcommands].each do |subcommand| -%>
27
30
  <%= subcommand[:name] %>)
28
31
  <%= function_name %>_<%= subcommand[:name] %>
29
32
  ;;
33
+ <%- subcommand[:aliases].each do |_alias| -%>
34
+ <%= _alias %>)
35
+ <%= function_name %>_<%= subcommand[:name] %>
36
+ ;;
37
+ <%- end -%>
30
38
  <%- end -%>
31
39
  *)
32
40
  # if does not match any subcommand
@@ -41,11 +49,11 @@
41
49
  <%= function_name %>() {
42
50
  _arguments \
43
51
  <%- subcommand[:options].each do |option| -%>
44
- {<%= option[:names].join(",") %>}<%= option[:description].gsub(/'/, "''") if option[:description] %> \
52
+ <%= escape_option_names(option[:names]) %><%= quote(bracket(option[:description])) if option[:description] %> \
45
53
  <%- end -%>
46
54
  '*: :->rest'
47
55
 
48
- case $state in
56
+ case ${state:?} in
49
57
  rest)
50
58
  # complete rest arguments
51
59
  _files
@@ -1,5 +1,5 @@
1
1
  class Thor
2
2
  module ZshCompletion
3
- VERSION = "0.1.1"
3
+ VERSION = "0.1.7".freeze
4
4
  end
5
5
  end
@@ -1,7 +1,6 @@
1
- # coding: utf-8
2
- lib = File.expand_path('../lib', __FILE__)
1
+ lib = File.expand_path("lib", __dir__)
3
2
  $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
- require 'thor/zsh_completion/version'
3
+ require "thor/zsh_completion/version"
5
4
 
6
5
  Gem::Specification.new do |spec|
7
6
  spec.name = "thor-zsh_completion"
@@ -9,17 +8,15 @@ Gem::Specification.new do |spec|
9
8
  spec.authors = ["labocho"]
10
9
  spec.email = ["labocho@penguinlab.jp"]
11
10
 
12
- spec.summary = %q{Create zsh completion script for Thor subclass}
13
- spec.description = %q{Create zsh completion script for Thor subclass}
11
+ spec.summary = "Create zsh completion script for Thor subclass"
12
+ spec.description = "Create zsh completion script for Thor subclass"
14
13
  spec.homepage = "https://github.com/labocho/thor-zsh_completion"
15
14
  spec.license = "MIT"
16
15
 
17
- spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
16
+ spec.files = `git ls-files -z`.split("\x0").reject {|f| f.match(%r{^(test|spec|features)/}) }
18
17
  spec.bindir = "exe"
19
- spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
18
+ spec.executables = spec.files.grep(%r(^exe/)) {|f| File.basename(f) }
20
19
  spec.require_paths = ["lib"]
21
20
 
22
- spec.add_development_dependency "bundler", "~> 1.10"
23
- spec.add_development_dependency "rake", "~> 10.0"
24
- spec.add_development_dependency "rspec"
21
+ spec.add_dependency "thor", "~> 0"
25
22
  end
metadata CHANGED
@@ -1,62 +1,27 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: thor-zsh_completion
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
5
- prerelease:
4
+ version: 0.1.7
6
5
  platform: ruby
7
6
  authors:
8
7
  - labocho
9
8
  autorequire:
10
9
  bindir: exe
11
10
  cert_chain: []
12
- date: 2016-01-28 00:00:00.000000000 Z
11
+ date: 2020-06-25 00:00:00.000000000 Z
13
12
  dependencies:
14
13
  - !ruby/object:Gem::Dependency
15
- name: bundler
14
+ name: thor
16
15
  requirement: !ruby/object:Gem::Requirement
17
- none: false
18
16
  requirements:
19
- - - ~>
20
- - !ruby/object:Gem::Version
21
- version: '1.10'
22
- type: :development
23
- prerelease: false
24
- version_requirements: !ruby/object:Gem::Requirement
25
- none: false
26
- requirements:
27
- - - ~>
28
- - !ruby/object:Gem::Version
29
- version: '1.10'
30
- - !ruby/object:Gem::Dependency
31
- name: rake
32
- requirement: !ruby/object:Gem::Requirement
33
- none: false
34
- requirements:
35
- - - ~>
36
- - !ruby/object:Gem::Version
37
- version: '10.0'
38
- type: :development
39
- prerelease: false
40
- version_requirements: !ruby/object:Gem::Requirement
41
- none: false
42
- requirements:
43
- - - ~>
44
- - !ruby/object:Gem::Version
45
- version: '10.0'
46
- - !ruby/object:Gem::Dependency
47
- name: rspec
48
- requirement: !ruby/object:Gem::Requirement
49
- none: false
50
- requirements:
51
- - - ! '>='
17
+ - - "~>"
52
18
  - !ruby/object:Gem::Version
53
19
  version: '0'
54
- type: :development
20
+ type: :runtime
55
21
  prerelease: false
56
22
  version_requirements: !ruby/object:Gem::Requirement
57
- none: false
58
23
  requirements:
59
- - - ! '>='
24
+ - - "~>"
60
25
  - !ruby/object:Gem::Version
61
26
  version: '0'
62
27
  description: Create zsh completion script for Thor subclass
@@ -66,15 +31,19 @@ executables: []
66
31
  extensions: []
67
32
  extra_rdoc_files: []
68
33
  files:
69
- - .gitignore
70
- - .rspec
71
- - .travis.yml
34
+ - ".gitignore"
35
+ - ".rspec"
36
+ - ".rubocop.yml"
37
+ - ".travis.yml"
38
+ - CHANGELOG.md
72
39
  - CODE_OF_CONDUCT.md
73
40
  - Gemfile
74
41
  - LICENSE.txt
75
42
  - README.md
76
43
  - Rakefile
77
44
  - bin/console
45
+ - bin/rspec
46
+ - bin/rubocop
78
47
  - bin/setup
79
48
  - lib/thor/zsh_completion.rb
80
49
  - lib/thor/zsh_completion/command.rb
@@ -86,26 +55,24 @@ files:
86
55
  homepage: https://github.com/labocho/thor-zsh_completion
87
56
  licenses:
88
57
  - MIT
58
+ metadata: {}
89
59
  post_install_message:
90
60
  rdoc_options: []
91
61
  require_paths:
92
62
  - lib
93
63
  required_ruby_version: !ruby/object:Gem::Requirement
94
- none: false
95
64
  requirements:
96
- - - ! '>='
65
+ - - ">="
97
66
  - !ruby/object:Gem::Version
98
67
  version: '0'
99
68
  required_rubygems_version: !ruby/object:Gem::Requirement
100
- none: false
101
69
  requirements:
102
- - - ! '>='
70
+ - - ">="
103
71
  - !ruby/object:Gem::Version
104
72
  version: '0'
105
73
  requirements: []
106
- rubyforge_project:
107
- rubygems_version: 1.8.23.2
74
+ rubygems_version: 3.1.2
108
75
  signing_key:
109
- specification_version: 3
76
+ specification_version: 4
110
77
  summary: Create zsh completion script for Thor subclass
111
78
  test_files: []