Skip to content

Commit

Permalink
bashly generate --quiet
Browse files Browse the repository at this point in the history
  • Loading branch information
wolfgang42 committed Sep 30, 2021
1 parent 42c3ce0 commit 4bbb17b
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 6 deletions.
11 changes: 6 additions & 5 deletions lib/bashly/commands/generate.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,12 @@ module Commands
class Generate < Base
help "Generate the bash script and required files"

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

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

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

private

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

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

Expand All @@ -50,7 +51,7 @@ def create_all_command_files

def create_file(file, content)
if File.exist? file and !args['--force']
say "skipped !txtgrn!#{file}!txtrst! (exists)"
say "skipped !txtgrn!#{file}!txtrst! (exists)" unless args['--quiet']
else
File.write file, content
say "created !txtgrn!#{file}"
Expand All @@ -60,7 +61,7 @@ def create_file(file, content)
def create_master_script
File.write master_script_path, script.code
FileUtils.chmod "+x", master_script_path
say "created !txtgrn!#{master_script_path}"
say "created !txtgrn!#{master_script_path}" unless args['--quiet']
end

def script
Expand Down
5 changes: 4 additions & 1 deletion spec/approvals/cli/generate/help
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
Generate the bash script and required files

Usage:
bashly generate [--force --wrap FUNCTION]
bashly generate [--force --quiet --wrap FUNCTION]
bashly generate (-h|--help)

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

-q --quiet
Less verbose output

-h --help
Show this help

Expand Down
3 changes: 3 additions & 0 deletions spec/approvals/cli/generate/quiet
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
created spec/tmp/src/initialize.sh
created spec/tmp/src/download_command.sh
created spec/tmp/src/upload_command.sh
28 changes: 28 additions & 0 deletions spec/bashly/commands/generate_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,34 @@
end
end

context "with --quiet" do
let(:cli_script) { "#{target_dir}/cli" }

before do
reset_tmp_dir
success = system "mkdir -p #{source_dir} && cp lib/bashly/templates/bashly.yml #{source_dir}/bashly.yml"
expect(success).to be true
end

it "generates the cli script" do
expect { subject.run %w[generate --quiet] }.to output_approval('cli/generate/quiet')
expect(File).to exist(cli_script)
end

context "when source files already exist" do
before do
expect { subject.run %w[generate --quiet] } #.to output_nothing
File.write "#{source_dir}/download_command.sh", "some new user content"
end

it "does not overwrite them" do
expect { subject.run %w[generate --quiet] } #.to output_nothing
expect(File.read "#{source_dir}/download_command.sh").to eq "some new user content"
end
end

end

context "with --wrap function" do
let(:cli_script) { "#{target_dir}/cli" }

Expand Down

0 comments on commit 4bbb17b

Please sign in to comment.