Skip to content

Commit 4bbb17b

Browse files
committed
bashly generate --quiet
1 parent 42c3ce0 commit 4bbb17b

File tree

4 files changed

+41
-6
lines changed

4 files changed

+41
-6
lines changed

lib/bashly/commands/generate.rb

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,12 @@ module Commands
33
class Generate < Base
44
help "Generate the bash script and required files"
55

6-
usage "bashly generate [--force --wrap FUNCTION]"
6+
usage "bashly generate [--force --quiet --wrap FUNCTION]"
77
usage "bashly generate (-h|--help)"
88

99
option "-f --force", "Overwrite existing files"
1010
option "-w --wrap FUNCTION", "Wrap the entire script in a function so it can also be sourced"
11+
option "-q --quiet", "Less verbose output"
1112

1213
environment "BASHLY_SOURCE_DIR", "The path containing the bashly configuration and source files [default: src]"
1314
environment "BASHLY_TARGET_DIR", "The path to use for creating the bash script [default: .]"
@@ -18,13 +19,13 @@ class Generate < Base
1819
def run
1920
create_user_files
2021
create_master_script
21-
say "run !txtpur!#{master_script_path} --help!txtrst! to test your bash script"
22+
say "run !txtpur!#{master_script_path} --help!txtrst! to test your bash script" unless args['--quiet']
2223
end
2324

2425
private
2526

2627
def create_user_files
27-
say "creating user files in !txtgrn!#{Settings.source_dir}"
28+
say "creating user files in !txtgrn!#{Settings.source_dir}" unless args['--quiet']
2829

2930
create_file "#{Settings.source_dir}/initialize.sh", command.render(:default_initialize_script)
3031

@@ -50,7 +51,7 @@ def create_all_command_files
5051

5152
def create_file(file, content)
5253
if File.exist? file and !args['--force']
53-
say "skipped !txtgrn!#{file}!txtrst! (exists)"
54+
say "skipped !txtgrn!#{file}!txtrst! (exists)" unless args['--quiet']
5455
else
5556
File.write file, content
5657
say "created !txtgrn!#{file}"
@@ -60,7 +61,7 @@ def create_file(file, content)
6061
def create_master_script
6162
File.write master_script_path, script.code
6263
FileUtils.chmod "+x", master_script_path
63-
say "created !txtgrn!#{master_script_path}"
64+
say "created !txtgrn!#{master_script_path}" unless args['--quiet']
6465
end
6566

6667
def script

spec/approvals/cli/generate/help

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
Generate the bash script and required files
22

33
Usage:
4-
bashly generate [--force --wrap FUNCTION]
4+
bashly generate [--force --quiet --wrap FUNCTION]
55
bashly generate (-h|--help)
66

77
Options:
@@ -11,6 +11,9 @@ Options:
1111
-w --wrap FUNCTION
1212
Wrap the entire script in a function so it can also be sourced
1313

14+
-q --quiet
15+
Less verbose output
16+
1417
-h --help
1518
Show this help
1619

spec/approvals/cli/generate/quiet

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
created spec/tmp/src/initialize.sh
2+
created spec/tmp/src/download_command.sh
3+
created spec/tmp/src/upload_command.sh

spec/bashly/commands/generate_spec.rb

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,34 @@
5151
end
5252
end
5353

54+
context "with --quiet" do
55+
let(:cli_script) { "#{target_dir}/cli" }
56+
57+
before do
58+
reset_tmp_dir
59+
success = system "mkdir -p #{source_dir} && cp lib/bashly/templates/bashly.yml #{source_dir}/bashly.yml"
60+
expect(success).to be true
61+
end
62+
63+
it "generates the cli script" do
64+
expect { subject.run %w[generate --quiet] }.to output_approval('cli/generate/quiet')
65+
expect(File).to exist(cli_script)
66+
end
67+
68+
context "when source files already exist" do
69+
before do
70+
expect { subject.run %w[generate --quiet] } #.to output_nothing
71+
File.write "#{source_dir}/download_command.sh", "some new user content"
72+
end
73+
74+
it "does not overwrite them" do
75+
expect { subject.run %w[generate --quiet] } #.to output_nothing
76+
expect(File.read "#{source_dir}/download_command.sh").to eq "some new user content"
77+
end
78+
end
79+
80+
end
81+
5482
context "with --wrap function" do
5583
let(:cli_script) { "#{target_dir}/cli" }
5684

0 commit comments

Comments
 (0)