bashly 1.3.8 → 1.4.0.rc1

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.
@@ -1,155 +1,141 @@
1
- bashly:
2
- - --help
3
- - -h
4
- - --version
5
- - -v
6
- - init
7
- - preview
8
- - validate
9
- - generate
10
- - add
11
- - doc
12
- - completions
13
- - shell
14
-
15
- bashly init: &init
16
- - --help
17
- - -h
18
- - --minimal
19
- - -m
20
-
21
- bashly i: *init
22
-
23
- bashly preview: &preview
24
- - --help
25
- - -h
26
-
27
- bashly p: *preview
28
-
29
- bashly validate: &validate
30
- - --help
31
- - -h
32
- - --verbose
33
- - -v
34
-
35
- bashly v: *validate
36
-
37
- bashly generate: &generate
38
- - --help
39
- - -h
40
- - --env
41
- - --force
42
- - --quiet
43
- - --upgrade
44
- - --watch
45
- - --wrap
46
- - -e
47
- - -f
48
- - -q
49
- - -r
50
- - -u
51
- - -w
52
-
53
- bashly g: *generate
54
-
55
- bashly generate*--env: &env
56
- - development
57
- - production
58
-
59
- bashly generate*-e: *env
60
- bashly g*--env: *env
61
- bashly g*-e: *env
62
-
63
- bashly add: &add
64
- - --help
65
- - -h
66
- - --force
67
- - --list
68
- - --source
69
- - -f
70
- - -l
71
- - -s
72
- - colors
73
- - completions
74
- - completions_script
75
- - completions_yaml
76
- - config
77
- - help
78
- - hooks
79
- - lib
80
- - settings
81
- - strings
82
- - test
83
- - validations
84
- - yaml
85
-
86
- bashly a: *add
87
-
88
- bashly doc: &doc
89
- - --help
90
- - -h
91
- - --index
92
- - -i
93
- - arg
94
- - arg.allowed
95
- - arg.default
96
- - arg.help
97
- - arg.name
98
- - arg.repeatable
99
- - arg.required
100
- - arg.validate
101
- - command
102
- - command.alias
103
- - command.args
104
- - command.catch_all
105
- - command.commands
106
- - command.completions
107
- - command.default
108
- - command.dependencies
109
- - command.environment_variables
110
- - command.examples
111
- - command.expose
112
- - command.extensible
113
- - command.filename
114
- - command.filters
115
- - command.flags
116
- - command.footer
117
- - command.function
118
- - command.group
119
- - command.help
120
- - command.name
121
- - command.private
122
- - command.version
123
- - environment_variable
124
- - environment_variable.default
125
- - environment_variable.help
126
- - environment_variable.name
127
- - environment_variable.private
128
- - environment_variable.required
129
- - flag
130
- - flag.allowed
131
- - flag.arg
132
- - flag.completions
133
- - flag.conflicts
134
- - flag.default
135
- - flag.help
136
- - flag.long
137
- - flag.private
138
- - flag.repeatable
139
- - flag.required
140
- - flag.short
141
- - flag.validate
142
-
143
- bashly completions: &completions
144
- - --help
145
- - -h
146
- - --install
147
- - -i
148
-
149
- bashly c: *completions
150
-
151
- bashly shell: &shell
152
- - --help
153
- - -h
154
-
155
- bashly s: *shell
1
+ patterns:
2
+ - bashly [root options]
3
+ - bashly init|i [init options]
4
+ - bashly preview|p [preview options]
5
+ - bashly validate|v [validate options]
6
+ - bashly generate|build|g [generate options]
7
+ - bashly add|a [add options] <library>
8
+ - bashly doc [doc options] <doc>
9
+ - bashly completions|c [completions options]
10
+ - bashly render [render options] <render_source>
11
+ - bashly shell|s [shell options]
12
+
13
+ options:
14
+ root:
15
+ - --help|-h
16
+ - --version|-v
17
+ init:
18
+ - --help|-h
19
+ - --minimal|-m
20
+ preview:
21
+ - --help|-h
22
+ validate:
23
+ - --help|-h
24
+ - --verbose|-v
25
+ generate:
26
+ - --help|-h
27
+ - --env|-e <env>
28
+ - --force|-f
29
+ - --quiet|-q
30
+ - --upgrade|-u
31
+ - --watch|-w
32
+ - --wrap|-r <function>
33
+ add:
34
+ - --help|-h
35
+ - --force|-f
36
+ - --list|-l
37
+ - --source|-s <source>
38
+ doc:
39
+ - --help|-h
40
+ - --index|-i
41
+ completions:
42
+ - --help|-h
43
+ - --install|-i
44
+ - --uninstall|-u
45
+ render:
46
+ - --help|-h
47
+ - --watch|-w
48
+ - --show|-s <path>
49
+ - --list|-l
50
+ - --about|-a
51
+ shell:
52
+ - --help|-h
53
+
54
+ tokens:
55
+ env:
56
+ - development
57
+ - production
58
+ function:
59
+ source:
60
+ path:
61
+ library:
62
+ - colors
63
+ - completions
64
+ - completions_script
65
+ - completions_yaml
66
+ - config
67
+ - help
68
+ - hooks
69
+ - ini
70
+ - lib
71
+ - render_markdown
72
+ - render_markdown_github
73
+ - render_mandoc
74
+ - settings
75
+ - stacktrace
76
+ - strings
77
+ - validations
78
+ - yaml
79
+ doc:
80
+ - arg
81
+ - arg.allowed
82
+ - arg.completions
83
+ - arg.default
84
+ - arg.help
85
+ - arg.name
86
+ - arg.repeatable
87
+ - arg.required
88
+ - arg.validate
89
+ - command
90
+ - command.alias
91
+ - command.args
92
+ - command.catch_all
93
+ - command.commands
94
+ - command.completions
95
+ - command.default
96
+ - command.dependencies
97
+ - command.environment_variables
98
+ - command.examples
99
+ - command.expose
100
+ - command.extensible
101
+ - command.filename
102
+ - command.filters
103
+ - command.flags
104
+ - command.footer
105
+ - command.function
106
+ - command.group
107
+ - command.help
108
+ - command.help_header_override
109
+ - command.name
110
+ - command.private
111
+ - command.variables
112
+ - command.version
113
+ - environment_variable
114
+ - environment_variable.default
115
+ - environment_variable.help
116
+ - environment_variable.name
117
+ - environment_variable.private
118
+ - environment_variable.required
119
+ - environment_variable.validate
120
+ - flag
121
+ - flag.allowed
122
+ - flag.arg
123
+ - flag.completions
124
+ - flag.conflicts
125
+ - flag.default
126
+ - flag.help
127
+ - flag.long
128
+ - flag.needs
129
+ - flag.private
130
+ - flag.repeatable
131
+ - flag.required
132
+ - flag.short
133
+ - flag.unique
134
+ - flag.validate
135
+ - variable
136
+ - variable.name
137
+ - variable.value
138
+ render_source:
139
+ - ":mandoc"
140
+ - ":markdown"
141
+ - ":markdown_github"
@@ -1,85 +1,72 @@
1
- > bashly:
1
+ > patterns:
2
+ > - bashly [root options]
3
+ > - bashly init|i [init options]
4
+ > - bashly preview|p [preview options]
5
+ > - bashly validate|v [validate options]
6
+ > - bashly generate|build|g [generate options]
7
+ > - bashly add|a [add options] <library>
8
+ > - bashly doc [doc options] <doc>
9
+ > - bashly completions|c [completions options]
10
+ > - bashly render [render options] <render_source>
11
+ > - bashly shell|s [shell options]
12
+ >
13
+ > options:
14
+ > root:
2
15
  = help_flags
3
- > - --version
4
- > - -v
5
- commands.each do |command|
6
- = "- #{command}"
7
- end
8
- >
9
- > bashly init: &init
16
+ > - --version|-v
17
+ > init:
18
+ = help_flags
19
+ > - --minimal|-m
20
+ > preview:
21
+ = help_flags
22
+ > validate:
10
23
  = help_flags
11
- > - --minimal
12
- > - -m
13
- >
14
- > bashly i: *init
15
- >
16
- > bashly preview: &preview
24
+ > - --verbose|-v
25
+ > generate:
17
26
  = help_flags
18
- >
19
- > bashly p: *preview
20
- >
21
- > bashly validate: &validate
27
+ > - --env|-e <env>
28
+ > - --force|-f
29
+ > - --quiet|-q
30
+ > - --upgrade|-u
31
+ > - --watch|-w
32
+ > - --wrap|-r <function>
33
+ > add:
22
34
  = help_flags
23
- > - --verbose
24
- > - -v
25
- >
26
- > bashly v: *validate
27
- >
28
- > bashly generate: &generate
35
+ > - --force|-f
36
+ > - --list|-l
37
+ > - --source|-s <source>
38
+ > doc:
29
39
  = help_flags
30
- > - --env
31
- > - --force
32
- > - --quiet
33
- > - --upgrade
34
- > - --watch
35
- > - --wrap
36
- > - -e
37
- > - -f
38
- > - -q
39
- > - -r
40
- > - -u
41
- > - -w
42
- >
43
- > bashly g: *generate
44
- >
45
- > bashly generate*--env: &env
46
- > - development
47
- > - production
48
- >
49
- > bashly generate*-e: *env
50
- > bashly g*--env: *env
51
- > bashly g*-e: *env
52
- >
53
- > bashly add: &add
40
+ > - --index|-i
41
+ > completions:
54
42
  = help_flags
55
- > - --force
56
- > - --list
57
- > - --source
58
- > - -f
59
- > - -l
60
- > - -s
43
+ > - --install|-i
44
+ > - --uninstall|-u
45
+ > render:
46
+ = help_flags
47
+ > - --watch|-w
48
+ > - --show|-s <path>
49
+ > - --list|-l
50
+ > - --about|-a
51
+ > shell:
52
+ = help_flags
53
+ >
54
+ > tokens:
55
+ > env:
56
+ > - development
57
+ > - production
58
+ > function:
59
+ > source:
60
+ > path:
61
+ > library:
61
62
  libs.each do |lib|
62
- = "- #{lib}"
63
+ = " - #{lib}"
63
64
  end
64
- >
65
- > bashly a: *add
66
- >
67
- > bashly doc: &doc
68
- = help_flags
69
- > - --index
70
- > - -i
65
+ > doc:
71
66
  docs.each do |doc|
72
- = "- #{doc}"
67
+ = " - #{doc}"
68
+ end
69
+ > render_source:
70
+ render_sources.each do |source|
71
+ = " - #{source.inspect}"
73
72
  end
74
- >
75
- > bashly completions: &completions
76
- = help_flags
77
- > - --install
78
- > - -i
79
- >
80
- > bashly c: *completions
81
- >
82
- > bashly shell: &shell
83
- = help_flags
84
- >
85
- > bashly s: *shell
@@ -1,4 +1,5 @@
1
1
  require 'completely'
2
+ require 'bashly/completion_builder'
2
3
 
3
4
  module Bashly
4
5
  # This is a `Command` and `Flag` concern responsible for providing bash
@@ -15,25 +16,18 @@ module Bashly
15
16
  ["#{prefix}#{name}", comps]
16
17
  end
17
18
  end
19
+
20
+ def completion_option_entry(token_name = nil)
21
+ result = [aliases.join('|')]
22
+ result << "<#{token_name}>" if token_name
23
+ result << '(repeatable)' if repeatable
24
+ result.join ' '
25
+ end
18
26
  end
19
27
 
20
28
  module Command
21
29
  def completion_data(with_version: true)
22
- result = {}
23
-
24
- completion_full_names.each do |name|
25
- name = "#{name}*" if name.include? '*'
26
- result[name] = completion_words with_version: with_version
27
- flags.each do |flag|
28
- result.merge! flag.completion_data(name)
29
- end
30
- end
31
-
32
- visible_commands.each do |command|
33
- result.merge! command.completion_data(with_version: false)
34
- end
35
-
36
- result
30
+ CompletionBuilder.new(self, with_version: with_version).call
37
31
  end
38
32
 
39
33
  def completion_script
@@ -44,42 +38,11 @@ module Bashly
44
38
  completion_generator.wrapper_function name
45
39
  end
46
40
 
47
- protected
48
-
49
- def completion_full_names
50
- if parent_command
51
- glue = parent_command.global_flags? ? '*' : ' '
52
- parent_command.completion_full_names.product(aliases).map { |a| a.join glue }
53
- else
54
- aliases
55
- end
56
- end
57
-
58
41
  private
59
42
 
60
43
  def completion_generator
61
44
  Completely::Completions.new completion_data
62
45
  end
63
-
64
- def completion_flag_names
65
- visible_flags.map(&:name) + visible_flags.map(&:short)
66
- end
67
-
68
- def completion_allowed_args
69
- args.map(&:allowed).flatten
70
- end
71
-
72
- def completion_words(with_version: false)
73
- trivial_flags = %w[--help -h]
74
- trivial_flags += %w[--version -v] if with_version
75
- all = (
76
- visible_command_aliases + trivial_flags +
77
- completion_flag_names + completion_allowed_args
78
- )
79
-
80
- all += completions if completions
81
- all.compact.uniq.sort
82
- end
83
46
  end
84
47
  end
85
48
  end
@@ -90,6 +90,8 @@ module Bashly
90
90
 
91
91
  def assert_arg(key, value)
92
92
  assert_hash key, value, keys: Script::Argument.option_keys
93
+ refute value['allowed'] && value['completions'], "#{key} cannot have both nub`allowed` and nub`completions`"
94
+
93
95
  assert_string "#{key}.name", value['name']
94
96
  assert_optional_string "#{key}.help", value['help']
95
97
  assert_string_or_array "#{key}.default", value['default']
@@ -99,6 +101,7 @@ module Bashly
99
101
  assert_boolean "#{key}.unique", value['unique']
100
102
 
101
103
  assert_array "#{key}.allowed", value['allowed'], of: :string
104
+ assert_array "#{key}.completions", value['completions'], of: :string
102
105
 
103
106
  refute value['name'].match(/^-/), "#{key}.name must not start with '-'"
104
107
 
@@ -33,6 +33,17 @@ arg.allowed:
33
33
  allowed: [stage, production, development]
34
34
  default: development
35
35
 
36
+ arg.completions:
37
+ help: Specify a list of additional completion suggestions when used in conjunction with `bashly add completions`.
38
+ url: https://bashly.dev/configuration/argument/#completions
39
+ example: |-
40
+ args:
41
+ - name: path
42
+ help: File or directory to process
43
+ completions:
44
+ - <file>
45
+ - <directory>
46
+
36
47
  arg.default:
37
48
  help: Specify the value to apply when not provided by the user.
38
49
  url: https://bashly.dev/configuration/argument/#default
@@ -2,14 +2,21 @@ require 'erb'
2
2
  require 'yaml'
3
3
 
4
4
  module YAML
5
- # We trust our loaded YAMLs
6
- # This patch is due to https://bugs.ruby-lang.org/issues/17866
7
- # StackOverflow: https://stackoverflow.com/questions/71191685/visit-psych-nodes-alias-unknown-alias-default-psychbadalias/71192990#71192990
8
5
  class << self
9
- alias load unsafe_load if YAML.respond_to? :unsafe_load
6
+ def trusted_load(content)
7
+ if YAML.respond_to? :unsafe_load
8
+ YAML.unsafe_load content
9
+ else
10
+ YAML.load content
11
+ end
12
+ end
13
+
14
+ def trusted_load_file(path)
15
+ trusted_load File.read(path)
16
+ end
10
17
 
11
18
  def load_erb_file(path)
12
- YAML.load ERB.new(File.read(path)).result
19
+ YAML.trusted_load ERB.new(File.read(path)).result
13
20
  end
14
21
  end
15
22
  end
@@ -79,6 +79,21 @@ render_markdown:
79
79
 
80
80
  m`$ bashly render templates/markdown docs`
81
81
 
82
+ render_markdown_github:
83
+ help: Copy the github markdown templates to your project, allowing you to customize the markdown documentation output.
84
+ skip_src_check: true
85
+ files:
86
+ - source: "render/markdown_github/README.md"
87
+ target: "templates/markdown_github/README.md"
88
+ - source: "render/markdown_github/markdown.gtx"
89
+ target: "templates/markdown_github/markdown.gtx"
90
+ - source: "render/markdown_github/render.rb"
91
+ target: "templates/markdown_github/render.rb"
92
+ post_install_message: |
93
+ Generate your markdown documentation by running:
94
+
95
+ m`$ bashly render templates/markdown_github docs`
96
+
82
97
  render_mandoc:
83
98
  help: Copy the mandoc templates to your project, allowing you to customize the man documentation output.
84
99
  skip_src_check: true
@@ -9,7 +9,7 @@ module Bashly
9
9
  end
10
10
 
11
11
  def data
12
- @data ||= YAML.load_file path
12
+ @data ||= YAML.trusted_load_file path
13
13
  end
14
14
 
15
15
  def validated_data
@@ -13,7 +13,7 @@ module Bashly
13
13
  private
14
14
 
15
15
  def values!
16
- defaults = YAML.load_file asset('libraries/strings/strings.yml')
16
+ defaults = YAML.trusted_load_file asset('libraries/strings/strings.yml')
17
17
  defaults.merge project_strings
18
18
  end
19
19
 
@@ -23,7 +23,7 @@ module Bashly
23
23
 
24
24
  def project_strings!
25
25
  if File.exist? project_strings_path
26
- YAML.load_file project_strings_path
26
+ YAML.trusted_load_file project_strings_path
27
27
  else
28
28
  {}
29
29
  end
@@ -8,7 +8,7 @@ module Bashly
8
8
  class << self
9
9
  def option_keys
10
10
  @option_keys ||= %i[
11
- allowed default help name repeatable required unique validate
11
+ allowed completions default help name repeatable required unique validate
12
12
  ]
13
13
  end
14
14
  end
@@ -27,7 +27,7 @@ module Bashly
27
27
  def initialize(label: nil, commands: nil, help: nil)
28
28
  @label = label
29
29
  @commands = commands.is_a?(String) ? [commands] : commands
30
- @help = help&.empty? ? nil : help
30
+ @help = help && help.empty? ? nil : help
31
31
  end
32
32
 
33
33
  def multi?
@@ -1,3 +1,3 @@
1
1
  module Bashly
2
- VERSION = '1.3.8'
2
+ VERSION = '1.4.0.rc1'
3
3
  end
data/lib/bashly.rb CHANGED
@@ -6,8 +6,9 @@ module Bashly
6
6
  autoloads 'bashly/refinements', %i[ComposeRefinements]
7
7
 
8
8
  autoloads 'bashly', %i[
9
- CLI Config ConfigValidator Library LibrarySource LibrarySourceConfig
10
- MessageStrings RenderContext RenderSource Settings VERSION Watch
9
+ CLI CompletionBuilder Config ConfigValidator Library LibrarySource
10
+ LibrarySourceConfig MessageStrings RenderContext RenderSource Settings
11
+ VERSION Watch
11
12
  ]
12
13
 
13
14
  autoloads 'bashly/concerns', %i[