diff --git a/Runfile b/Runfile index 31e458a0..079dff1a 100644 --- a/Runfile +++ b/Runfile @@ -1,7 +1,9 @@ require "runfile-tasks" require "byebug" +require "colsole" require_relative 'lib/bashly' require_relative 'helpers/example' +include Colsole title "Bashly Developer Toolbelt" summary "Runfile tasks for building the Bashly gem" diff --git a/lib/bashly/commands/generate.rb b/lib/bashly/commands/generate.rb index 7c3e3c0b..c759f264 100644 --- a/lib/bashly/commands/generate.rb +++ b/lib/bashly/commands/generate.rb @@ -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", "Disable on-screen progress report" 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: .]" @@ -18,13 +19,17 @@ class Generate < Base def run create_user_files create_master_script - say "run !txtpur!#{master_script_path} --help!txtrst! to test your bash script" + quiet_say "run !txtpur!#{master_script_path} --help!txtrst! to test your bash script" end private + def quiet_say(message) + say message unless args['--quiet'] + end + def create_user_files - say "creating user files in !txtgrn!#{Settings.source_dir}" + quiet_say "creating user files in !txtgrn!#{Settings.source_dir}" create_file "#{Settings.source_dir}/initialize.sh", command.render(:default_initialize_script) @@ -50,17 +55,17 @@ def create_all_command_files def create_file(file, content) if File.exist? file and !args['--force'] - say "skipped !txtgrn!#{file}!txtrst! (exists)" + quiet_say "skipped !txtgrn!#{file}!txtrst! (exists)" else File.write file, content - say "created !txtgrn!#{file}" + quiet_say "created !txtgrn!#{file}" end end def create_master_script File.write master_script_path, script.code FileUtils.chmod "+x", master_script_path - say "created !txtgrn!#{master_script_path}" + quiet_say "created !txtgrn!#{master_script_path}" end def script diff --git a/spec/approvals/cli/generate/help b/spec/approvals/cli/generate/help index b64cdf53..650f24b0 100644 --- a/spec/approvals/cli/generate/help +++ b/spec/approvals/cli/generate/help @@ -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: @@ -11,6 +11,9 @@ Options: -w --wrap FUNCTION Wrap the entire script in a function so it can also be sourced + -q --quiet + Disable on-screen progress report + -h --help Show this help diff --git a/spec/bashly/commands/generate_spec.rb b/spec/bashly/commands/generate_spec.rb index 88eace50..256df250 100644 --- a/spec/bashly/commands/generate_spec.rb +++ b/spec/bashly/commands/generate_spec.rb @@ -28,12 +28,12 @@ context "when source files already exist" do before do expect { subject.run %w[generate] }.to output_approval('cli/generate/no-args') - File.write "#{source_dir}/cli_get_command.sh", "some new user content" + File.write "#{source_dir}/download_command.sh", "some new user content" end it "does not overwrite them" do expect { subject.run %w[generate] }.to output_approval('cli/generate/no-args-skip') - expect(File.read "#{source_dir}/cli_get_command.sh").to eq "some new user content" + expect(File.read "#{source_dir}/download_command.sh").to eq "some new user content" end end @@ -51,6 +51,21 @@ 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_not output.to_stdout + expect(File).to exist(cli_script) + end + end + context "with --wrap function" do let(:cli_script) { "#{target_dir}/cli" }