Skip to content
Merged
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
2 changes: 2 additions & 0 deletions Runfile
Original file line number Diff line number Diff line change
@@ -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
17 changes: 11 additions & 6 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", "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 @@ -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)

Expand All @@ -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
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
Disable on-screen progress report

-h --help
Show this help

Expand Down
19 changes: 17 additions & 2 deletions spec/bashly/commands/generate_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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" }

Expand Down