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
16 changes: 13 additions & 3 deletions examples/help-command/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,9 @@ This example was generated with:

```bash
$ bashly init
$ bashly add help
# ... now edit src/bashly.yml to match the example ...
$ bashly generate
# ... now edit src/help_command.sh to match the example ...
$ bashly generate

```

Expand Down Expand Up @@ -88,6 +87,18 @@ commands:
## `src/help_command.sh`

```bash
## Help command [@bashly-upgrade help]
## This file is a part of Bashly standard library
##
## Add this as a command to your bashly.yml:
##
## commands:
## - name: help
## help: Show help about a command
## args:
## - name: command
## help: Help subject
##
command="${args[command]}"
long_usage=yes

Expand All @@ -107,7 +118,6 @@ else
exit 1
fi


```


Expand Down
13 changes: 12 additions & 1 deletion examples/help-command/src/help_command.sh
Original file line number Diff line number Diff line change
@@ -1,3 +1,15 @@
## Help command [@bashly-upgrade help]
## This file is a part of Bashly standard library
##
## Add this as a command to your bashly.yml:
##
## commands:
## - name: help
## help: Show help about a command
## args:
## - name: command
## help: Help subject
##
command="${args[command]}"
long_usage=yes

Expand All @@ -16,4 +28,3 @@ else
echo "No help available for this command"
exit 1
fi

3 changes: 3 additions & 0 deletions examples/help-command/test.sh
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
#!/usr/bin/env bash

rm -f src/*.sh

set -x

bashly add help
bashly generate

### Try Me ###
Expand Down
18 changes: 12 additions & 6 deletions lib/bashly/commands/add.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ class Add < Base
usage 'bashly add colors [--force]'
usage 'bashly add comp FORMAT [OUTPUT --force]'
usage 'bashly add config [--force]'
usage 'bashly add help [--force]'
usage 'bashly add lib [--force]'
usage 'bashly add settings [--force]'
usage 'bashly add strings [--force]'
Expand All @@ -32,6 +33,7 @@ class Add < Base
command 'colors', 'Add standard functions for printing colorful and formatted text to the lib directory.'
command 'comp', 'Generate a bash completions script or function.'
command 'config', 'Add standard functions for handling INI files to the lib directory.'
command 'help', 'Add a help command, in addition to the standard --help flag.'
command 'lib', 'Create the additional lib directory for additional user scripts. All *.sh scripts in this ' \
'folder will be included in the final bash script.'

Expand Down Expand Up @@ -74,6 +76,10 @@ def config_command
add_lib 'config'
end

def lib_command
add_lib 'lib'
end

def settings_command
@skip_src_check = true
add_lib 'settings'
Expand All @@ -83,22 +89,22 @@ def strings_command
add_lib 'strings'
end

def lib_command
add_lib 'lib'
end

def test_command
add_lib 'test'
end

def yaml_command
add_lib 'yaml'
def help_command
add_lib 'help'
end

def validations_command
add_lib 'validations'
end

def yaml_command
add_lib 'yaml'
end

private

def add_lib(name, *args)
Expand Down
2 changes: 2 additions & 0 deletions lib/bashly/libraries.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ config:
- source: "templates/lib/config.sh"
target: "%{user_lib_dir}/config.sh"

help: :Help

lib:
files:
- source: "templates/lib/sample_function.sh"
Expand Down
10 changes: 10 additions & 0 deletions lib/bashly/libraries/base.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,16 @@ def files
def post_install_message
nil
end

protected

def command
@command ||= Script::Command.new config
end

def config
@config ||= Config.new "#{Settings.source_dir}/bashly.yml"
end
end
end
end
15 changes: 0 additions & 15 deletions lib/bashly/libraries/completions.rb

This file was deleted.

2 changes: 1 addition & 1 deletion lib/bashly/libraries/completions_function.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
module Bashly
module Libraries
class CompletionsFunction < Completions
class CompletionsFunction < Base
def files
[
{
Expand Down
2 changes: 1 addition & 1 deletion lib/bashly/libraries/completions_script.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
module Bashly
module Libraries
class CompletionsScript < Completions
class CompletionsScript < Base
def files
[
{
Expand Down
2 changes: 1 addition & 1 deletion lib/bashly/libraries/completions_yaml.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
module Bashly
module Libraries
class CompletionsYAML < Completions
class CompletionsYAML < Base
def files
[
{
Expand Down
36 changes: 36 additions & 0 deletions lib/bashly/libraries/help.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
module Bashly
module Libraries
class Help < Base
include AssetHelper

def files
[
{
path: "#{Settings.source_dir}/help_command.sh",
content: help_command,
},
]
end

def post_install_message
<<~MESSAGE
Add this as a command to your bashly.yml:

!txtgrn!commands:
!txtgrn!- name: !txtpur!help
!txtgrn! help: !txtpur!Show help about a command
!txtgrn! args:
!txtgrn!- name: !txtpur!command
!txtgrn! help: !txtpur!Help subject

MESSAGE
end

private

def help_command
asset_content('templates/help/help_command.sh') % { name: command.name }
end
end
end
end
30 changes: 30 additions & 0 deletions lib/bashly/templates/help/help_command.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
## Help command [@bashly-upgrade help]
## This file is a part of Bashly standard library
##
## Add this as a command to your bashly.yml:
##
## commands:
## - name: help
## help: Show help about a command
## args:
## - name: command
## help: Help subject
##
command="${args[command]}"
long_usage=yes

if [[ -z "$command" ]]; then
# No command argument, show the global help
help_function=%{name}_usage
else
# Show the help for the requested command
help_function="%{name}_${command}_usage"
fi

# Call the help function if it exists
if [[ $(type -t "$help_function") ]]; then
"$help_function"
else
echo "No help available for this command"
exit 1
fi
4 changes: 4 additions & 0 deletions spec/approvals/cli/add/help
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ Usage:
bashly add colors [--force]
bashly add comp FORMAT [OUTPUT --force]
bashly add config [--force]
bashly add help [--force]
bashly add lib [--force]
bashly add settings [--force]
bashly add strings [--force]
Expand All @@ -23,6 +24,9 @@ Commands:
config
Add standard functions for handling INI files to the lib directory.

help
Add a help command, in addition to the standard --help flag.

lib
Create the additional lib directory for additional user scripts. All *.sh
scripts in this folder will be included in the final bash script.
Expand Down
12 changes: 12 additions & 0 deletions spec/approvals/cli/add/help_command
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
created spec/tmp/src/help_command.sh

Add this as a command to your bashly.yml:

commands:
- name: help
help: Show help about a command
args:
- name: command
help: Help subject


2 changes: 0 additions & 2 deletions spec/approvals/cli/add/init

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ Usage:
bashly add colors [--force]
bashly add comp FORMAT [OUTPUT --force]
bashly add config [--force]
bashly add help [--force]
bashly add lib [--force]
bashly add settings [--force]
bashly add strings [--force]
Expand Down
19 changes: 16 additions & 3 deletions spec/approvals/examples/help-command
Original file line number Diff line number Diff line change
@@ -1,9 +1,22 @@
+ bashly add help
created src/help_command.sh

Add this as a command to your bashly.yml:

commands:
- name: help
help: Show help about a command
args:
- name: command
help: Help subject


+ bashly generate
creating user files in src
skipped src/initialize.sh (exists)
created src/initialize.sh
skipped src/help_command.sh (exists)
skipped src/download_command.sh (exists)
skipped src/upload_command.sh (exists)
created src/download_command.sh
created src/upload_command.sh
created ./cli
run ./cli --help to test your bash script
+ ./cli
Expand Down
1 change: 1 addition & 0 deletions spec/approvals/library/config-keys
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
- completions_script
- completions_yaml
- config
- help
- lib
- settings
- strings
Expand Down
Loading