Skip to content

Commit 783fc32

Browse files
authored
Merge pull request #112 from DannyBen/pr/109
Fix and merge #109, #110 and #111
2 parents 42c3ce0 + 3583394 commit 783fc32

File tree

4 files changed

+34
-9
lines changed

4 files changed

+34
-9
lines changed

Runfile

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
require "runfile-tasks"
22
require "byebug"
3+
require "colsole"
34
require_relative 'lib/bashly'
45
require_relative 'helpers/example'
6+
include Colsole
57

68
title "Bashly Developer Toolbelt"
79
summary "Runfile tasks for building the Bashly gem"

lib/bashly/commands/generate.rb

Lines changed: 11 additions & 6 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", "Disable on-screen progress report"
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,17 @@ 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+
quiet_say "run !txtpur!#{master_script_path} --help!txtrst! to test your bash script"
2223
end
2324

2425
private
2526

27+
def quiet_say(message)
28+
say message unless args['--quiet']
29+
end
30+
2631
def create_user_files
27-
say "creating user files in !txtgrn!#{Settings.source_dir}"
32+
quiet_say "creating user files in !txtgrn!#{Settings.source_dir}"
2833

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

@@ -50,17 +55,17 @@ def create_all_command_files
5055

5156
def create_file(file, content)
5257
if File.exist? file and !args['--force']
53-
say "skipped !txtgrn!#{file}!txtrst! (exists)"
58+
quiet_say "skipped !txtgrn!#{file}!txtrst! (exists)"
5459
else
5560
File.write file, content
56-
say "created !txtgrn!#{file}"
61+
quiet_say "created !txtgrn!#{file}"
5762
end
5863
end
5964

6065
def create_master_script
6166
File.write master_script_path, script.code
6267
FileUtils.chmod "+x", master_script_path
63-
say "created !txtgrn!#{master_script_path}"
68+
quiet_say "created !txtgrn!#{master_script_path}"
6469
end
6570

6671
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+
Disable on-screen progress report
16+
1417
-h --help
1518
Show this help
1619

spec/bashly/commands/generate_spec.rb

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,12 +28,12 @@
2828
context "when source files already exist" do
2929
before do
3030
expect { subject.run %w[generate] }.to output_approval('cli/generate/no-args')
31-
File.write "#{source_dir}/cli_get_command.sh", "some new user content"
31+
File.write "#{source_dir}/download_command.sh", "some new user content"
3232
end
3333

3434
it "does not overwrite them" do
3535
expect { subject.run %w[generate] }.to output_approval('cli/generate/no-args-skip')
36-
expect(File.read "#{source_dir}/cli_get_command.sh").to eq "some new user content"
36+
expect(File.read "#{source_dir}/download_command.sh").to eq "some new user content"
3737
end
3838
end
3939

@@ -51,6 +51,21 @@
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_not output.to_stdout
65+
expect(File).to exist(cli_script)
66+
end
67+
end
68+
5469
context "with --wrap function" do
5570
let(:cli_script) { "#{target_dir}/cli" }
5671

0 commit comments

Comments
 (0)