Skip to content

Commit 5567311

Browse files
authored
Merge pull request #612 from DannyBen/add/bashly-add-quiet-flag
Add `--quiet` to `bashly add` command
2 parents 43e0244 + ca0a546 commit 5567311

File tree

5 files changed

+22
-4
lines changed

5 files changed

+22
-4
lines changed

lib/bashly/commands/add.rb

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ module Commands
33
class Add < Base
44
help 'Add extra features and customization to your script'
55

6-
usage 'bashly add [--source NAME] LIBRARY [ARGS...] [--force]'
6+
usage 'bashly add [--source NAME] LIBRARY [ARGS...] [--force --quiet]'
77
usage 'bashly add [--source NAME] --list'
88
usage 'bashly add (-h|--help)'
99

@@ -17,6 +17,7 @@ class Add < Base
1717
USAGE
1818
option '-f --force', 'Overwrite existing files'
1919
option '-l --list', 'Show available libraries'
20+
option '-q --quiet', 'Do not show post-install messages'
2021

2122
attr_reader :skip_src_check
2223

@@ -70,7 +71,9 @@ def add_library_files(library)
7071
end
7172

7273
message = library.post_install_message
73-
say "\n#{message}" if message && files_created.positive?
74+
return if !message || files_created.zero? || args['--quiet']
75+
76+
say "\n#{message}"
7477
end
7578

7679
def safe_write(path, content)

spec/approvals/cli/add/colors-quiet

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
created spec/tmp/src/lib/colors.sh

spec/approvals/cli/add/help

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
Add extra features and customization to your script
22

33
Usage:
4-
bashly add [--source NAME] LIBRARY [ARGS...] [--force]
4+
bashly add [--source NAME] LIBRARY [ARGS...] [--force --quiet]
55
bashly add [--source NAME] --list
66
bashly add (-h|--help)
77

@@ -20,5 +20,8 @@ Options:
2020
-l --list
2121
Show available libraries
2222

23+
-q --quiet
24+
Do not show post-install messages
25+
2326
-h --help
2427
Show this help

spec/approvals/cli/add/usage

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
Usage:
2-
bashly add [--source NAME] LIBRARY [ARGS...] [--force]
2+
bashly add [--source NAME] LIBRARY [ARGS...] [--force --quiet]
33
bashly add [--source NAME] --list
44
bashly add (-h|--help)

spec/bashly/commands/add_spec.rb

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,17 @@
4747
end
4848
end
4949

50+
describe 'add colors --quiet' do
51+
let(:lib_file) { "#{source_dir}/lib/colors.sh" }
52+
53+
before { reset_tmp_dir create_src: true }
54+
55+
it 'does not show the post-install message' do
56+
expect { subject.execute %w[add colors --quiet] }.to output_approval('cli/add/colors-quiet')
57+
expect(File).to exist(lib_file)
58+
end
59+
end
60+
5061
describe 'add completions' do
5162
before { reset_tmp_dir init: true }
5263

0 commit comments

Comments
 (0)