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

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions examples/colors/colorly
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,14 @@ initialize() {
version="0.1.0"
long_usage=''
set -e

# :src/initialize.sh
# Code here runs inside the initialize() function
# Use it for anything that you need to run before any other function, like
# setting environment vairables:
# CONFIG_FILE=settings.ini
#
# Feel free to empty (but not delete) this file.
}

# :command.run
Expand Down
6 changes: 6 additions & 0 deletions examples/colors/src/initialize.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# Code here runs inside the initialize() function
# Use it for anything that you need to run before any other function, like
# setting environment vairables:
# CONFIG_FILE=settings.ini
#
# Feel free to empty (but not delete) this file.
8 changes: 8 additions & 0 deletions examples/config-ini/configly
Original file line number Diff line number Diff line change
Expand Up @@ -505,6 +505,14 @@ initialize() {
version="0.1.0"
long_usage=''
set -e

# :src/initialize.sh
# Code here runs inside the initialize() function
# Use it for anything that you need to run before any other function, like
# setting environment vairables:
# CONFIG_FILE=settings.ini
#
# Feel free to empty (but not delete) this file.
}

# :command.run
Expand Down
6 changes: 6 additions & 0 deletions examples/config-ini/src/initialize.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# Code here runs inside the initialize() function
# Use it for anything that you need to run before any other function, like
# setting environment vairables:
# CONFIG_FILE=settings.ini
#
# Feel free to empty (but not delete) this file.
8 changes: 8 additions & 0 deletions examples/custom-includes/download
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,14 @@ initialize() {
version="0.1.0"
long_usage=''
set -e

# :src/initialize.sh
# Code here runs inside the initialize() function
# Use it for anything that you need to run before any other function, like
# setting environment vairables:
# CONFIG_FILE=settings.ini
#
# Feel free to empty (but not delete) this file.
}

# :command.run
Expand Down
6 changes: 6 additions & 0 deletions examples/custom-includes/src/initialize.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# Code here runs inside the initialize() function
# Use it for anything that you need to run before any other function, like
# setting environment vairables:
# CONFIG_FILE=settings.ini
#
# Feel free to empty (but not delete) this file.
8 changes: 8 additions & 0 deletions examples/custom-strings/download
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,14 @@ initialize() {
version="0.1.0"
long_usage=''
set -e

# :src/initialize.sh
# Code here runs inside the initialize() function
# Use it for anything that you need to run before any other function, like
# setting environment vairables:
# CONFIG_FILE=settings.ini
#
# Feel free to empty (but not delete) this file.
}

# :command.run
Expand Down
6 changes: 6 additions & 0 deletions examples/custom-strings/src/initialize.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# Code here runs inside the initialize() function
# Use it for anything that you need to run before any other function, like
# setting environment vairables:
# CONFIG_FILE=settings.ini
#
# Feel free to empty (but not delete) this file.
8 changes: 8 additions & 0 deletions examples/minimal/download
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,14 @@ initialize() {
version="0.1.0"
long_usage=''
set -e

# :src/initialize.sh
# Code here runs inside the initialize() function
# Use it for anything that you need to run before any other function, like
# setting environment vairables:
# CONFIG_FILE=settings.ini
#
# Feel free to empty (but not delete) this file.
}

# :command.run
Expand Down
6 changes: 6 additions & 0 deletions examples/minimal/src/initialize.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# Code here runs inside the initialize() function
# Use it for anything that you need to run before any other function, like
# setting environment vairables:
# CONFIG_FILE=settings.ini
#
# Feel free to empty (but not delete) this file.
8 changes: 8 additions & 0 deletions examples/subcommands/cli
Original file line number Diff line number Diff line change
Expand Up @@ -373,6 +373,14 @@ initialize() {
version="0.1.0"
long_usage=''
set -e

# :src/initialize.sh
# Code here runs inside the initialize() function
# Use it for anything that you need to run before any other function, like
# setting environment vairables:
# CONFIG_FILE=settings.ini
#
# Feel free to empty (but not delete) this file.
}

# :command.run
Expand Down
6 changes: 6 additions & 0 deletions examples/subcommands/src/initialize.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# Code here runs inside the initialize() function
# Use it for anything that you need to run before any other function, like
# setting environment vairables:
# CONFIG_FILE=settings.ini
#
# Feel free to empty (but not delete) this file.
14 changes: 12 additions & 2 deletions lib/bashly/commands/generate.rb
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,20 @@ def run
def create_user_files
say "creating user files in !txtgrn!#{Settings.source_dir}"

create_file "#{Settings.source_dir}/initialize.sh", command.render(:default_initialize_script)

if command.commands.empty?
create_file "#{Settings.source_dir}/root_command.sh", command.render(:default_root_script)
create_root_command_file
else
create_all_command_files
end

end

def create_root_command_file
create_file "#{Settings.source_dir}/root_command.sh", command.render(:default_root_script)
end

def create_all_command_files
command.commands.each do |subcommand|
file = "#{Settings.source_dir}/#{subcommand.full_name.to_underscore}_command.sh"
content = subcommand.render :default_script
Expand Down
9 changes: 6 additions & 3 deletions lib/bashly/models/command.rb
Original file line number Diff line number Diff line change
Expand Up @@ -50,13 +50,16 @@ def full_name
# Reads a file from the userspace (Settings.source_dir) and returns
# its contents.
# If the file is not found, returns a string with a hint.
def load_user_file(file)
def load_user_file(file, placeholder: true)
path = "#{Settings.source_dir}/#{file}"
default_content = placeholder ? "# error: cannot load file" : ''

content = if File.exist? path
File.read path
else
"# error: cannot load file"
else
default_content
end

"# :#{path}\n#{content}"
end

Expand Down
6 changes: 6 additions & 0 deletions lib/bashly/views/command/default_initialize_script.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# Code here runs inside the initialize() function
# Use it for anything that you need to run before any other function, like
# setting environment vairables:
# CONFIG_FILE=settings.ini
#
# Feel free to empty (but not delete) this file.
2 changes: 2 additions & 0 deletions lib/bashly/views/command/initialize.erb
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,6 @@ initialize() {
version="<%= version %>"
long_usage=''
set -e

<%= load_user_file("initialize.sh", placeholder: false).indent 2 %>
}
1 change: 1 addition & 0 deletions spec/approvals/cli/generate/minimal
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
creating user files in spec/tmp/src
created spec/tmp/src/initialize.sh
created spec/tmp/src/root_command.sh
created spec/tmp/download
run spec/tmp/download --help to test your bash script
1 change: 1 addition & 0 deletions spec/approvals/cli/generate/no-args
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
creating user files in spec/tmp/src
created spec/tmp/src/initialize.sh
created spec/tmp/src/cli_download_command.sh
created spec/tmp/src/cli_upload_command.sh
created spec/tmp/cli
Expand Down
3 changes: 2 additions & 1 deletion spec/approvals/cli/generate/no-args-skip
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
creating user files in spec/tmp/src
skipped spec/tmp/src/cli_download_command.sh (exists)
skipped spec/tmp/src/initialize.sh (exists)
skipped spec/tmp/src/cli_download_command.sh (exists)
skipped spec/tmp/src/cli_upload_command.sh (exists)
created spec/tmp/cli
run spec/tmp/cli --help to test your bash script
1 change: 1 addition & 0 deletions spec/approvals/examples/colors
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
+ bashly generate
creating user files in src
created src/initialize.sh
skipped src/root_command.sh (exists)
created ./colorly
run ./colorly --help to test your bash script
Expand Down
1 change: 1 addition & 0 deletions spec/approvals/examples/config-ini
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
+ bashly generate
creating user files in src
created src/initialize.sh
skipped src/configly_set_command.sh (exists)
skipped src/configly_get_command.sh (exists)
skipped src/configly_list_command.sh (exists)
Expand Down
1 change: 1 addition & 0 deletions spec/approvals/examples/custom-includes
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
+ bashly generate
creating user files in src
created src/initialize.sh
skipped src/root_command.sh (exists)
created ./download
run ./download --help to test your bash script
Expand Down
1 change: 1 addition & 0 deletions spec/approvals/examples/custom-strings
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
+ bashly generate
creating user files in src
created src/initialize.sh
created src/root_command.sh
created ./download
run ./download --help to test your bash script
Expand Down
1 change: 1 addition & 0 deletions spec/approvals/examples/minimal
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
+ bashly generate
creating user files in src
created src/initialize.sh
created src/root_command.sh
created ./download
run ./download --help to test your bash script
Expand Down
1 change: 1 addition & 0 deletions spec/approvals/examples/short-flag
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
+ bashly generate
creating user files in src
created src/initialize.sh
created src/rush_config_command.sh
created src/rush_get_command.sh
created ./rush
Expand Down
1 change: 1 addition & 0 deletions spec/approvals/examples/subcommands
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
+ bashly generate
creating user files in src
created src/initialize.sh
created src/cli_download_command.sh
created src/cli_upload_command.sh
created ./cli
Expand Down