atli 0.1.8 → 0.1.9

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
  SHA1:
3
- metadata.gz: 13e61f293aa7bde2e5ac7b0db815fbe5c7a40751
4
- data.tar.gz: f01468bc2b2ec632e392086fe36c068c0eb412f4
3
+ metadata.gz: d1d536b28ea563e34f3d78cede54f2a9d8c21da2
4
+ data.tar.gz: 67573792a5172033627abd159a41bd9f0f1bb983
5
5
  SHA512:
6
- metadata.gz: f1c315d604b47905681f2a811fc2540730c5a0607159409e6c8c84c05a838dd8385267e011ba30ba1f1369fba15a8917f4cc798738f699d7de3733abab32f9d5
7
- data.tar.gz: 12ccd0e704f4a91e51be8b126b8d1f2657924835a9c5a2baef20d308b9168e1b1ca69acb6f7236adf87ad4e703111dd719872a46c1c38d66094fb9a048c2f20f
6
+ metadata.gz: 30da74bbb70ca3aa22595a13f6a984cddeec184e189fdce51c19ddc7c2eca8d5be9e400ab5bfb945e71b6d530ccd852f6932388aacb069178eafeaa1c9346786
7
+ data.tar.gz: 4923f187d07c5a41bf4d47bdff6a90e47ddaf79c07cba061381c4eda383d8fd9e445494b8b22f306625c1c99895df1d5b0e4afac9f296eebb0a55e4ca06894e4
@@ -23,7 +23,7 @@ Gem::Specification.new do |spec|
23
23
  # ============================================================================
24
24
 
25
25
  # My guns
26
- spec.add_dependency "nrser", '~> 0.3.5'
26
+ spec.add_dependency "nrser", '~> 0.3.8'
27
27
 
28
28
 
29
29
  # Development Dependencies
@@ -3,9 +3,11 @@ require 'nrser'
3
3
  require 'semantic_logger'
4
4
  require "thor/base"
5
5
  require 'thor/example'
6
+ require 'thor/completion/bash'
6
7
 
7
8
 
8
9
  class Thor
10
+ include Thor::Completion::Bash::Thor
9
11
 
10
12
  class << self
11
13
  # Allows for custom "Command" package naming.
@@ -1,4 +1,5 @@
1
1
  require 'semantic_logger'
2
+ require_relative './completion/bash'
2
3
 
3
4
  class Thor
4
5
  class Command < Struct.new( :name,
@@ -9,6 +10,7 @@ class Thor
9
10
  :options,
10
11
  :ancestor_name )
11
12
  include SemanticLogger::Loggable
13
+ include Thor::Completion::Bash::Command
12
14
 
13
15
  FILE_REGEXP = /^#{Regexp.escape(File.dirname(__FILE__))}/
14
16
 
@@ -0,0 +1,162 @@
1
+ # encoding: UTF-8
2
+ # frozen_string_literal: true
3
+
4
+ # Requirements
5
+ # =======================================================================
6
+
7
+ # Stdlib
8
+ # -----------------------------------------------------------------------
9
+
10
+ # Deps
11
+ # -----------------------------------------------------------------------
12
+
13
+ require 'nrser'
14
+ require 'nrser/labs/i8'
15
+
16
+ # Project / Package
17
+ # -----------------------------------------------------------------------
18
+
19
+
20
+ # Refinements
21
+ # =======================================================================
22
+
23
+ require 'nrser/refinements/types'
24
+ using NRSER::Types
25
+
26
+
27
+ # Namespace
28
+ # =======================================================================
29
+
30
+ class Thor
31
+ module Completion
32
+
33
+
34
+ # Definitions
35
+ # =======================================================================
36
+
37
+ # Experimental support for Bash completions.
38
+ #
39
+ module Bash
40
+
41
+ Request = I8::Struct.new \
42
+ cur: t.str,
43
+ prev: t.str,
44
+ cword: t.non_neg_int,
45
+ split: t.bool,
46
+ words: t.array( t.str )
47
+
48
+ # Needs to be mixed in to {Thor}. It's all class methods at the moment.
49
+ #
50
+ # @todo
51
+ # Deal with that {Thor::Group} thing? I never use it...
52
+ #
53
+ module Thor
54
+
55
+ # Methods to be mixed as class methods in to {Thor}.
56
+ #
57
+ module ClassMethods
58
+
59
+ # Get this class' {Thor::Command} instances, keyed by how their names will
60
+ # appear in the UI (replace `_` with `-`).
61
+ #
62
+ # @param [Boolean] include_hidden:
63
+ # When `true`, "hidden" commands will also be included.
64
+ #
65
+ # @return [Hash<String, Thor::Command>]
66
+ #
67
+ def all_commands_by_ui_name include_hidden: false
68
+ all_commands.
69
+ each_with_object( {} ) { |(name, cmd), hash|
70
+ next if cmd.hidden? && !include_hidden
71
+ hash[ name.tr( '_', '-' ) ] = cmd
72
+ }
73
+ end # .all_commands_by_ui_name
74
+
75
+ #
76
+ #
77
+ def bash_complete comp_req:, index:
78
+ # Find the command, if any
79
+
80
+ logger.info __method__,
81
+ comp_req: comp_req,
82
+ index: index,
83
+ word: comp_req.words[index]
84
+
85
+ scan_index = index
86
+
87
+ while (comp_req.words[scan_index] || '').start_with? '-'
88
+ scan_index += 1
89
+ end
90
+
91
+ cmd_ui_name = comp_req.words[scan_index] || ''
92
+
93
+ cmd = all_commands_by_ui_name[cmd_ui_name]
94
+
95
+ if cmd.nil?
96
+ return all_commands_by_ui_name.keys.select { |ui_name|
97
+ ui_name.start_with? cmd_ui_name
98
+ }
99
+ end
100
+
101
+ index = scan_index + 1
102
+
103
+ # is it a subcommand?
104
+ if subcommand_classes.key? cmd.name
105
+ # It is, hand it off to there
106
+ subcommand_classes[cmd.name].bash_complete \
107
+ comp_req: comp_req,
108
+ index: index
109
+ else
110
+ # It's a command, have that handle it
111
+ cmd.bash_complete \
112
+ comp_req: comp_req,
113
+ index: index
114
+ end
115
+ end
116
+
117
+ end # module ClassMethods
118
+
119
+ # Hook to mix {ClassMethods} in on include.
120
+ #
121
+ def self.included base
122
+ base.extend ClassMethods
123
+ end
124
+
125
+ end # module Thor
126
+
127
+
128
+ # Methods that need to mixed in to {Thor::Command}.
129
+ #
130
+ module Command
131
+
132
+ def bash_complete comp_req:, index:
133
+ # TODO Handle
134
+ return [] if comp_req.split
135
+
136
+ logger.info __method__,
137
+ cmd_name: name,
138
+ options: options
139
+
140
+ options.
141
+ each_with_object( [ '--help' ] ) { |(name, opt), results|
142
+ ui_name = name.to_s.tr( '_', '-' )
143
+
144
+ if opt.type == :boolean
145
+ results << "--#{ ui_name }"
146
+ results << "--no-#{ ui_name }"
147
+ else
148
+ results << "--#{ ui_name }="
149
+ end
150
+ }.
151
+ select { |term| term.start_with? comp_req.cur }
152
+ end
153
+
154
+ end # module Command
155
+
156
+ end # module Bash
157
+
158
+ # /Namespace
159
+ # =======================================================================
160
+
161
+ end # module Completion
162
+ end # class Thor
@@ -14,7 +14,7 @@ class Thor
14
14
  #
15
15
  # @return [String]
16
16
  #
17
- VERSION = '0.1.8'
17
+ VERSION = '0.1.9'
18
18
 
19
19
 
20
20
  # The version of Thor that Atli is up to date with.
@@ -27,5 +27,5 @@ class Thor
27
27
  #
28
28
  # @return [String]
29
29
  #
30
- THOR_VERSION = '0.1.8'
30
+ THOR_VERSION = '0.1.9'
31
31
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: atli
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.8
4
+ version: 0.1.9
5
5
  platform: ruby
6
6
  authors:
7
7
  - Neil Souza (Atli)
@@ -10,7 +10,7 @@ authors:
10
10
  autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
- date: 2018-05-25 00:00:00.000000000 Z
13
+ date: 2018-07-06 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: bundler
@@ -32,14 +32,14 @@ dependencies:
32
32
  requirements:
33
33
  - - "~>"
34
34
  - !ruby/object:Gem::Version
35
- version: 0.3.5
35
+ version: 0.3.8
36
36
  type: :runtime
37
37
  prerelease: false
38
38
  version_requirements: !ruby/object:Gem::Requirement
39
39
  requirements:
40
40
  - - "~>"
41
41
  - !ruby/object:Gem::Version
42
- version: 0.3.5
42
+ version: 0.3.8
43
43
  - !ruby/object:Gem::Dependency
44
44
  name: yard
45
45
  requirement: !ruby/object:Gem::Requirement
@@ -94,6 +94,7 @@ files:
94
94
  - lib/thor/base/class_methods.rb
95
95
  - lib/thor/base/common_class_options.rb
96
96
  - lib/thor/command.rb
97
+ - lib/thor/completion/bash.rb
97
98
  - lib/thor/core_ext/hash_with_indifferent_access.rb
98
99
  - lib/thor/core_ext/io_binary_read.rb
99
100
  - lib/thor/core_ext/ordered_hash.rb