bashly 0.3.4 → 0.3.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 7839064a69e5280ef2fcf0112ee9a4442912f99308a8c99dd3cf57c48fc905d2
4
- data.tar.gz: '0923d678dd93f16ec6beb2bb796e679b355fe971fc7141910c5b62d025ccfc4b'
3
+ metadata.gz: 95bc5fa6ee6c14e2e4cd269aecbfef7af9f005e7837c182c2f222d4640778e40
4
+ data.tar.gz: c8214a96d5d63094cb6f86e07022022f30b471da362b4aa087fe16ddaf96aada
5
5
  SHA512:
6
- metadata.gz: ec45676addca44ee7ce775b505d368b29723ed689e890592608a96a36fc64f8570dfd15a2df3a82b6a7e4bd2081db6338d11de0b285488d4af8145a83205cdb1
7
- data.tar.gz: cd6303a9834570a1d7a4a8d17ee796c72a116454cc1831af7a8897113419557840e1e1c94117abb06f9510dfb4b2aa4e7aafc67ce65eca2fcd0cd8ee56d0f8cd
6
+ metadata.gz: e25fd6d234783d9eb96a5e4f4a5bcc836740cbb6ee5ff2f5486a4fcea376a5e61c31f6b5eb762693708225ee8b2a2aac3d163d23d37d07dfe902687ee8d4a22b
7
+ data.tar.gz: 8bc3e1595cdb52c6001d55600f7fb4a1fda2d7d525b933641e04f4041de694354895eeb37d0e53d6c0cdc286b632643dfb812c8fb40cf958e93f94a5a005dcf5
data/README.md CHANGED
@@ -163,7 +163,7 @@ bash function.
163
163
  ### Flag options
164
164
 
165
165
  The flag's value will be available to you as `${args[--output]}` in your
166
- bash function (regardless of whether the user provided ut with the long or
166
+ bash function (regardless of whether the user provided it with the long or
167
167
  short form).
168
168
 
169
169
  Option | Description
@@ -174,6 +174,12 @@ short form).
174
174
  `arg` | If the flag requires an argument, specify its name here.
175
175
  `required` | Specify if this flag is required.
176
176
 
177
+ #### Special handling for -v and -h
178
+
179
+ The `-v` and `-h` flags will be used as the short options for `--version` and
180
+ `--help` respectively **only if you are not using them in any of your own
181
+ flags**.
182
+
177
183
  ### Environment Variable options
178
184
 
179
185
  The below configuration generates this environment variable usage text:
@@ -136,6 +136,11 @@ module Bashly
136
136
  parents.empty?
137
137
  end
138
138
 
139
+ # Returns true if one of the flags matches the provided short code
140
+ def short_flag_exist?(flag)
141
+ flags.select { |f| f.short == flag }.any?
142
+ end
143
+
139
144
  # Returns a constructed string suitable for Usage pattern
140
145
  def usage_string
141
146
  result = [full_name]
@@ -14,8 +14,6 @@ group: "%{group} Commands:"
14
14
  command_shortcut: "Shortcut: %{short}"
15
15
  default_command_summary: "%{summary} (default)"
16
16
  required: "(required)"
17
- help_flag: "--help | -h"
18
- version_flag: "--version"
19
17
 
20
18
  # Fixed flags help text
21
19
  help_flag_text: Show this help
@@ -1,3 +1,3 @@
1
1
  module Bashly
2
- VERSION = "0.3.4"
2
+ VERSION = "0.3.5"
3
3
  end
@@ -1,11 +1,19 @@
1
1
  # :command.fixed_flag_filter
2
2
  case "$1" in
3
+ <%- if short_flag_exist? "-v" -%>
3
4
  --version )
5
+ <%- else -%>
6
+ --version | -v )
7
+ <%- end -%>
4
8
  version_command
5
9
  exit 1
6
10
  ;;
7
11
 
8
- --help | -h )
12
+ <%- if short_flag_exist? "-h" -%>
13
+ --help )
14
+ <%- else -%>
15
+ --help | -h )
16
+ <%- end -%>
9
17
  long_usage=yes
10
18
  <%= function_name %>_usage
11
19
  exit 1
@@ -23,12 +23,12 @@
23
23
  printf "<%= strings[:usage] %>\n"
24
24
  printf " <%= usage_string %>\n"
25
25
  <%- if commands.any? -%>
26
- printf " <%= full_name %> [command] --help | -h\n"
26
+ printf " <%= full_name %> [command] --help<%= " | -h" unless short_flag_exist? "-h" -%>\n"
27
27
  <%- else -%>
28
- printf " <%= full_name %> <%= strings[:help_flag] %>\n"
28
+ printf " <%= full_name %> --help<%= " | -h" unless short_flag_exist? "-h" -%>\n"
29
29
  <%- end -%>
30
30
  <%- if root_command? -%>
31
- printf " <%= full_name %> <%= strings[:version_flag] %>\n"
31
+ printf " <%= full_name %> --version<%= " | -v" unless short_flag_exist? "-v" -%>\n"
32
32
  <%- end -%>
33
33
  echo
34
34
  <%= render(:usage_commands).indent 2 if commands.any? %>
@@ -1,9 +1,17 @@
1
1
  # :command.usage_fixed_flags
2
+ <%- if short_flag_exist? "-h" -%>
3
+ echo " --help"
4
+ <%- else -%>
2
5
  echo " --help, -h"
6
+ <%- end -%>
3
7
  printf " <%= strings[:help_flag_text] %>\n"
4
8
  echo
5
9
  <%- if root_command? -%>
10
+ <%- if short_flag_exist? "-v" -%>
6
11
  echo " --version"
12
+ <%- else -%>
13
+ echo " --version, -v"
14
+ <%- end -%>
7
15
  printf " <%= strings[:version_flag_text] %>\n"
8
16
  echo
9
17
  <%- end -%>
@@ -6,7 +6,7 @@
6
6
  shift
7
7
  shift
8
8
  else
9
- printf "<%= strings[:flag_requires_an_argument] % { long: long, usage: usage_string } %>\n"
9
+ printf "%s\n" "<%= strings[:flag_requires_an_argument] % { long: long, usage: usage_string } %>"
10
10
  exit 1
11
11
  fi
12
12
  <%- else -%>
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: bashly
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.4
4
+ version: 0.3.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Danny Ben Shitrit
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2019-12-19 00:00:00.000000000 Z
11
+ date: 2019-12-23 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: colsole