completely 0.5.3 → 0.5.4

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: a935ee0ae2ceb0c9c7b1f579c876a97068c45f133cfeaebcc2e6a6578216af22
4
- data.tar.gz: 624cc5668dd558f54aa8d66e6b6af765131c2f0a2442fe3c024247a52687a2fa
3
+ metadata.gz: e4fbe4bb19567637239bac887b5e785caeac6c0dbf38f82e7d775a994db58a29
4
+ data.tar.gz: d7449fd83d8e1b6e5ce723deb457e6e8eab4254a92818f739fd6002b939385c8
5
5
  SHA512:
6
- metadata.gz: 0a08c66582789427539a284b8b7e037643178cdfc602ea2621366fcd0de37bba34a6bd05a712ac5243e5538ddf19cc042549a9c6ecce1694cf8dabf5189f6e75
7
- data.tar.gz: e654bff7e530d8cb5414a1bcefe52081542041c57387c2b71cf61d8d49f26b2b8b5df96c648b51fa83594c828f597f8f0f814e7f6760fac3cc8f5c8fb5b76aa0
6
+ metadata.gz: e5e3c3985ac71d2db26ce7f321e1717af80ef760def41820b86e505ee884a3921d43618093c94ee41b3f9ed2291d35f9eac49fd6c4c6d4a376e1e981198d3ce9
7
+ data.tar.gz: 19719cecb29e21e1a226fd45d815a02baf9579c75e0f88ed0876a4ece8c3dee587feb88e71657d9d362cf9a2de5d0222b1423ecff4af759d32906daee0ba42a7
@@ -1,9 +1,10 @@
1
1
  require 'mister_bin'
2
+ require 'completely/version'
3
+ require 'completely/commands/generate'
2
4
  require 'completely/commands/init'
5
+ require 'completely/commands/install'
3
6
  require 'completely/commands/preview'
4
- require 'completely/commands/generate'
5
7
  require 'completely/commands/test'
6
- require 'completely/version'
7
8
 
8
9
  module Completely
9
10
  class CLI
@@ -16,6 +17,7 @@ module Completely
16
17
  runner.route 'preview', to: Commands::Preview
17
18
  runner.route 'generate', to: Commands::Generate
18
19
  runner.route 'test', to: Commands::Test
20
+ runner.route 'install', to: Commands::Install
19
21
 
20
22
  runner
21
23
  end
@@ -0,0 +1,96 @@
1
+ require 'completely/commands/base'
2
+
3
+ module Completely
4
+ module Commands
5
+ class Install < Base
6
+ TARGETS = %W[
7
+ /usr/share/bash-completion/completions
8
+ /usr/local/etc/bash_completion.d
9
+ #{Dir.home}/.bash_completion.d
10
+ ]
11
+
12
+ summary 'Install a bash completion script'
13
+
14
+ help <<~HELP
15
+ This command will copy the specified file to one of the following directories:
16
+
17
+ #{TARGETS.map { |c| " - #{c}" }.join "\n"}
18
+
19
+ The target filename will be the program name, and sudo will be used if necessary.
20
+ HELP
21
+
22
+ usage 'completely install PROGRAM [SCRIPT_PATH --force --dry]'
23
+ usage 'completely install (-h|--help)'
24
+
25
+ option '-f --force', 'Overwrite target file if it exists'
26
+ option '-d --dry', 'Show the installation command but do not run it'
27
+
28
+ param 'PROGRAM', 'Name of the program the completions are for.'
29
+ param 'SCRIPT_PATH', 'Path to the source bash script [default: completely.bash].'
30
+
31
+ def run
32
+ bounce
33
+
34
+ if args['--dry']
35
+ puts command.join ' '
36
+ return
37
+ end
38
+
39
+ success = system(*command)
40
+ raise "Failed running command:\nnb`#{command.join ' '}`" unless success
41
+
42
+ say "Saved m`#{target_path}`"
43
+ say 'You may need to restart your session to test it'
44
+ end
45
+
46
+ private
47
+
48
+ def bounce
49
+ unless completions_path
50
+ raise 'Cannot determine system completions directory'
51
+ end
52
+
53
+ unless File.exist? script_path
54
+ raise "Cannot find script: m`#{script_path}`"
55
+ end
56
+
57
+ if target_exist? && !args['--force']
58
+ raise "File exists: m`#{target_path}`\nUse nb`--force` to overwrite"
59
+ end
60
+ end
61
+
62
+ def target_exist?
63
+ File.exist? target_path
64
+ end
65
+
66
+ def command
67
+ result = root? ? [] : %w[sudo]
68
+ result + %W[cp #{script_path} #{target_path}]
69
+ end
70
+
71
+ def script_path
72
+ args['SCRIPT_PATH'] || 'completely.bash'
73
+ end
74
+
75
+ def target_path
76
+ "#{completions_path}/#{args['PROGRAM']}"
77
+ end
78
+
79
+ def root?
80
+ Process.uid.zero?
81
+ end
82
+
83
+ def completions_path
84
+ @completions_path ||= completions_path!
85
+ end
86
+
87
+ def completions_path!
88
+ TARGETS.each do |tarnet|
89
+ return tarnet if Dir.exist? tarnet
90
+ end
91
+
92
+ nil
93
+ end
94
+ end
95
+ end
96
+ end
@@ -1,3 +1,3 @@
1
1
  module Completely
2
- VERSION = '0.5.3'
2
+ VERSION = '0.5.4'
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: completely
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.5.3
4
+ version: 0.5.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Danny Ben Shitrit
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2023-01-31 00:00:00.000000000 Z
11
+ date: 2023-04-21 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: colsole
@@ -58,6 +58,7 @@ files:
58
58
  - lib/completely/commands/base.rb
59
59
  - lib/completely/commands/generate.rb
60
60
  - lib/completely/commands/init.rb
61
+ - lib/completely/commands/install.rb
61
62
  - lib/completely/commands/preview.rb
62
63
  - lib/completely/commands/test.rb
63
64
  - lib/completely/completions.rb
@@ -87,7 +88,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
87
88
  - !ruby/object:Gem::Version
88
89
  version: '0'
89
90
  requirements: []
90
- rubygems_version: 3.4.5
91
+ rubygems_version: 3.4.12
91
92
  signing_key:
92
93
  specification_version: 4
93
94
  summary: Bash Completions Generator