From 0aa53dba4d4127afa0c537b0eddd010f00b45f9e Mon Sep 17 00:00:00 2001 From: Danny Ben Shitrit Date: Thu, 30 Sep 2021 06:24:05 +0000 Subject: [PATCH] - Add --quiet to bashly generate --- Runfile | 2 ++ lib/bashly/commands/generate.rb | 16 ++++++++++------ spec/approvals/cli/generate/help | 2 +- spec/approvals/cli/generate/quiet | 3 --- spec/bashly/commands/generate_spec.rb | 15 +-------------- 5 files changed, 14 insertions(+), 24 deletions(-) delete mode 100644 spec/approvals/cli/generate/quiet 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 63f8a76a..c759f264 100644 --- a/lib/bashly/commands/generate.rb +++ b/lib/bashly/commands/generate.rb @@ -8,7 +8,7 @@ class Generate < Base 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" + 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: .]" @@ -19,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" unless args['--quiet'] + 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}" unless args['--quiet'] + quiet_say "creating user files in !txtgrn!#{Settings.source_dir}" create_file "#{Settings.source_dir}/initialize.sh", command.render(:default_initialize_script) @@ -51,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)" unless args['--quiet'] + 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}" unless args['--quiet'] + 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 810a76bb..650f24b0 100644 --- a/spec/approvals/cli/generate/help +++ b/spec/approvals/cli/generate/help @@ -12,7 +12,7 @@ Options: Wrap the entire script in a function so it can also be sourced -q --quiet - Less verbose output + Disable on-screen progress report -h --help Show this help diff --git a/spec/approvals/cli/generate/quiet b/spec/approvals/cli/generate/quiet deleted file mode 100644 index a67bf5b6..00000000 --- a/spec/approvals/cli/generate/quiet +++ /dev/null @@ -1,3 +0,0 @@ -created spec/tmp/src/initialize.sh -created spec/tmp/src/download_command.sh -created spec/tmp/src/upload_command.sh diff --git a/spec/bashly/commands/generate_spec.rb b/spec/bashly/commands/generate_spec.rb index 08cad6c2..22fa8053 100644 --- a/spec/bashly/commands/generate_spec.rb +++ b/spec/bashly/commands/generate_spec.rb @@ -61,22 +61,9 @@ end it "generates the cli script" do - expect { subject.run %w[generate --quiet] }.to output_approval('cli/generate/quiet') + expect { subject.run %w[generate --quiet] }.to_not output.to_stdout 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