Skip to content

Commit

Permalink
- Add --quiet to bashly generate
Browse files Browse the repository at this point in the history
  • Loading branch information
DannyBen committed Sep 30, 2021
1 parent 4bbb17b commit 0aa53db
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 24 deletions.
2 changes: 2 additions & 0 deletions 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"
Expand Down
16 changes: 10 additions & 6 deletions lib/bashly/commands/generate.rb
Expand Up @@ -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: .]"
Expand All @@ -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)

Expand All @@ -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
Expand Down
2 changes: 1 addition & 1 deletion spec/approvals/cli/generate/help
Expand Up @@ -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
Expand Down
3 changes: 0 additions & 3 deletions spec/approvals/cli/generate/quiet

This file was deleted.

15 changes: 1 addition & 14 deletions spec/bashly/commands/generate_spec.rb
Expand Up @@ -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
Expand Down

0 comments on commit 0aa53db

Please sign in to comment.