Skip to content

Commit 7b0a01f

Browse files
authored
Merge pull request #301 from DannyBen/add/help-command-library
Add help command library (bashly add help)
2 parents 24c0d95 + 617c366 commit 7b0a01f

File tree

20 files changed

+180
-67
lines changed

20 files changed

+180
-67
lines changed

examples/help-command/README.md

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,9 @@ This example was generated with:
88

99
```bash
1010
$ bashly init
11+
$ bashly add help
1112
# ... now edit src/bashly.yml to match the example ...
1213
$ bashly generate
13-
# ... now edit src/help_command.sh to match the example ...
14-
$ bashly generate
1514

1615
```
1716

@@ -88,6 +87,18 @@ commands:
8887
## `src/help_command.sh`
8988

9089
```bash
90+
## Help command [@bashly-upgrade help]
91+
## This file is a part of Bashly standard library
92+
##
93+
## Add this as a command to your bashly.yml:
94+
##
95+
## commands:
96+
## - name: help
97+
## help: Show help about a command
98+
## args:
99+
## - name: command
100+
## help: Help subject
101+
##
91102
command="${args[command]}"
92103
long_usage=yes
93104
@@ -107,7 +118,6 @@ else
107118
exit 1
108119
fi
109120
110-
111121
```
112122

113123

examples/help-command/src/help_command.sh

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,15 @@
1+
## Help command [@bashly-upgrade help]
2+
## This file is a part of Bashly standard library
3+
##
4+
## Add this as a command to your bashly.yml:
5+
##
6+
## commands:
7+
## - name: help
8+
## help: Show help about a command
9+
## args:
10+
## - name: command
11+
## help: Help subject
12+
##
113
command="${args[command]}"
214
long_usage=yes
315

@@ -16,4 +28,3 @@ else
1628
echo "No help available for this command"
1729
exit 1
1830
fi
19-

examples/help-command/test.sh

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,10 @@
11
#!/usr/bin/env bash
22

3+
rm -f src/*.sh
4+
35
set -x
46

7+
bashly add help
58
bashly generate
69

710
### Try Me ###

lib/bashly/commands/add.rb

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ class Add < Base
66
usage 'bashly add colors [--force]'
77
usage 'bashly add comp FORMAT [OUTPUT --force]'
88
usage 'bashly add config [--force]'
9+
usage 'bashly add help [--force]'
910
usage 'bashly add lib [--force]'
1011
usage 'bashly add settings [--force]'
1112
usage 'bashly add strings [--force]'
@@ -32,6 +33,7 @@ class Add < Base
3233
command 'colors', 'Add standard functions for printing colorful and formatted text to the lib directory.'
3334
command 'comp', 'Generate a bash completions script or function.'
3435
command 'config', 'Add standard functions for handling INI files to the lib directory.'
36+
command 'help', 'Add a help command, in addition to the standard --help flag.'
3537
command 'lib', 'Create the additional lib directory for additional user scripts. All *.sh scripts in this ' \
3638
'folder will be included in the final bash script.'
3739

@@ -74,6 +76,10 @@ def config_command
7476
add_lib 'config'
7577
end
7678

79+
def lib_command
80+
add_lib 'lib'
81+
end
82+
7783
def settings_command
7884
@skip_src_check = true
7985
add_lib 'settings'
@@ -83,22 +89,22 @@ def strings_command
8389
add_lib 'strings'
8490
end
8591

86-
def lib_command
87-
add_lib 'lib'
88-
end
89-
9092
def test_command
9193
add_lib 'test'
9294
end
9395

94-
def yaml_command
95-
add_lib 'yaml'
96+
def help_command
97+
add_lib 'help'
9698
end
9799

98100
def validations_command
99101
add_lib 'validations'
100102
end
101103

104+
def yaml_command
105+
add_lib 'yaml'
106+
end
107+
102108
private
103109

104110
def add_lib(name, *args)

lib/bashly/libraries.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@ config:
1212
- source: "templates/lib/config.sh"
1313
target: "%{user_lib_dir}/config.sh"
1414

15+
help: :Help
16+
1517
lib:
1618
files:
1719
- source: "templates/lib/sample_function.sh"

lib/bashly/libraries/base.rb

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,16 @@ def files
1414
def post_install_message
1515
nil
1616
end
17+
18+
protected
19+
20+
def command
21+
@command ||= Script::Command.new config
22+
end
23+
24+
def config
25+
@config ||= Config.new "#{Settings.source_dir}/bashly.yml"
26+
end
1727
end
1828
end
1929
end

lib/bashly/libraries/completions.rb

Lines changed: 0 additions & 15 deletions
This file was deleted.

lib/bashly/libraries/completions_function.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
module Bashly
22
module Libraries
3-
class CompletionsFunction < Completions
3+
class CompletionsFunction < Base
44
def files
55
[
66
{

lib/bashly/libraries/completions_script.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
module Bashly
22
module Libraries
3-
class CompletionsScript < Completions
3+
class CompletionsScript < Base
44
def files
55
[
66
{

lib/bashly/libraries/completions_yaml.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
module Bashly
22
module Libraries
3-
class CompletionsYAML < Completions
3+
class CompletionsYAML < Base
44
def files
55
[
66
{

0 commit comments

Comments
 (0)