File tree Expand file tree Collapse file tree 13 files changed +199
-30
lines changed
Expand file tree Collapse file tree 13 files changed +199
-30
lines changed Original file line number Diff line number Diff line change 11require 'mister_bin'
2- require 'completely/version'
32require 'completely/commands/generate'
43require 'completely/commands/init'
54require 'completely/commands/install'
65require 'completely/commands/preview'
76require 'completely/commands/test'
7+ require 'completely/commands/uninstall'
8+ require 'completely/version'
89
910module Completely
1011 class CLI
@@ -18,6 +19,7 @@ def self.runner
1819 runner . route 'generate' , to : Commands ::Generate
1920 runner . route 'test' , to : Commands ::Test
2021 runner . route 'install' , to : Commands ::Install
22+ runner . route 'uninstall' , to : Commands ::Uninstall
2123
2224 runner
2325 end
Original file line number Diff line number Diff line change @@ -21,12 +21,12 @@ class Install < Base
2121
2222 def run
2323 if args [ '--dry' ]
24- puts installer . command_string
24+ puts installer . install_command_string
2525 return
2626 end
2727
2828 success = installer . install force : args [ '--force' ]
29- raise InstallError , "Failed running command:\n nb`#{ installer . command_string } `" unless success
29+ raise InstallError , "Failed running command:\n nb`#{ installer . install_command_string } `" unless success
3030
3131 say "Saved m`#{ installer . target_path } `"
3232 say 'You may need to restart your session to test it'
Original file line number Diff line number Diff line change 1+ require 'completely/commands/base'
2+
3+ module Completely
4+ module Commands
5+ class Uninstall < Base
6+ summary 'Uninstall a bash completion script'
7+
8+ help <<~HELP
9+ This command will remove the completion script for the specified program from all the bash completion directories.
10+ HELP
11+
12+ usage 'completely uninstall PROGRAM [--dry]'
13+ usage 'completely uninstall (-h|--help)'
14+
15+ option '-d --dry' , 'Show the uninstallation command but do not run it'
16+
17+ param 'PROGRAM' , 'Name of the program the completions are for.'
18+
19+ def run
20+ if args [ '--dry' ]
21+ puts installer . uninstall_command_string
22+ return
23+ end
24+
25+ success = installer . uninstall
26+ raise InstallError , "Failed running command:\n nb`#{ installer . uninstall_command_string } `" unless success
27+
28+ say 'Done'
29+ say 'You may need to restart your session to test it'
30+ end
31+
32+ private
33+
34+ def installer
35+ Installer . new program : args [ 'PROGRAM' ]
36+ end
37+ end
38+ end
39+ end
Original file line number Diff line number Diff line change @@ -15,13 +15,22 @@ def target_directories
1515 ]
1616 end
1717
18- def command
18+ def install_command
1919 result = root_user? ? [ ] : %w[ sudo ]
2020 result + %W[ cp #{ script_path } #{ target_path } ]
2121 end
2222
23- def command_string
24- command . join ' '
23+ def install_command_string
24+ install_command . join ' '
25+ end
26+
27+ def uninstall_command
28+ result = root_user? ? [ ] : %w[ sudo ]
29+ result + %w[ rm -f ] + target_directories . map { |dir | "#{ dir } /#{ program } " }
30+ end
31+
32+ def uninstall_command_string
33+ uninstall_command . join ' '
2534 end
2635
2736 def target_path
@@ -41,7 +50,11 @@ def install(force: false)
4150 raise InstallError , "File exists: m`#{ target_path } `"
4251 end
4352
44- system ( *command )
53+ system ( *install_command )
54+ end
55+
56+ def uninstall
57+ system ( *uninstall_command )
4558 end
4659
4760 private
Original file line number Diff line number Diff line change 11Completely - Bash Completions Generator
22
33Commands:
4- init Create a new sample YAML configuration file
5- preview Generate the bash completion script to STDOUT
6- generate Generate the bash completion script to a file
7- test Test completions
8- install Install a bash completion script
4+ init Create a new sample YAML configuration file
5+ preview Generate the bash completion script to STDOUT
6+ generate Generate the bash completion script to a file
7+ test Test completions
8+ install Install a bash completion script
9+ uninstall Uninstall a bash completion script
910
1011Run completely COMMAND --help for more information
Original file line number Diff line number Diff line change 1+ sudo rm -f /usr/share/bash-completion/completions/completely-test /usr/local/etc/bash_completion.d/completely-test /home/vagrant/.bash_completion.d/completely-test
Original file line number Diff line number Diff line change 1+ Uninstall a bash completion script
2+
3+ This command will remove the completion script for the specified program from
4+ all the bash completion directories.
5+
6+ Usage:
7+ completely uninstall PROGRAM [--dry]
8+ completely uninstall (-h|--help)
9+
10+ Options:
11+ -d --dry
12+ Show the uninstallation command but do not run it
13+
14+ -h --help
15+ Show this help
16+
17+ Parameters:
18+ PROGRAM
19+ Name of the program the completions are for.
Original file line number Diff line number Diff line change 1+ Usage:
2+ completely uninstall PROGRAM [--dry]
3+ completely uninstall (-h|--help)
Original file line number Diff line number Diff line change 1+ Done
2+ You may need to restart your session to test it
Original file line number Diff line number Diff line change 1+ #<Completely::InstallError: Failed running command:
2+ nb`rm -f some paths`>
You can’t perform that action at this time.
0 commit comments