Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The rspec_approvals gem doesn't seem to like empty output, which is awkward in this situation. Since you're the creator of both gems I figured you'd have an idea about what to do here.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Well, it is by design. An empty output can be tested with .to be_empty and there is no need for an approval matcher. So, it is usually a mistake when you use any of the approval matches, with an empty output. But don't worry about it, I will take a deeper look in the spec and fix accordingly.

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