Skip to content

Commit f7ed693

Browse files
authored
Merge pull request #53 from DannyBen/add/uninstall
Add ability to uninstall a completion script
2 parents 8450c8f + 967e41f commit f7ed693

File tree

13 files changed

+199
-30
lines changed

13 files changed

+199
-30
lines changed

lib/completely/cli.rb

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
require 'mister_bin'
2-
require 'completely/version'
32
require 'completely/commands/generate'
43
require 'completely/commands/init'
54
require 'completely/commands/install'
65
require 'completely/commands/preview'
76
require 'completely/commands/test'
7+
require 'completely/commands/uninstall'
8+
require 'completely/version'
89

910
module 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

lib/completely/commands/install.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff 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:\nnb`#{installer.command_string}`" unless success
29+
raise InstallError, "Failed running command:\nnb`#{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'
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
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:\nnb`#{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

lib/completely/installer.rb

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff 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

spec/approvals/cli/commands

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
Completely - Bash Completions Generator
22

33
Commands:
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

1011
Run completely COMMAND --help for more information

spec/approvals/cli/uninstall/dry

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
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

spec/approvals/cli/uninstall/help

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
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.
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
Usage:
2+
completely uninstall PROGRAM [--dry]
3+
completely uninstall (-h|--help)
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
Done
2+
You may need to restart your session to test it
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
#<Completely::InstallError: Failed running command:
2+
nb`rm -f some paths`>

0 commit comments

Comments
 (0)