Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
vdesabou committed Oct 5, 2023
1 parent c240e33 commit 4c04b67
Show file tree
Hide file tree
Showing 8 changed files with 63 additions and 0 deletions.
2 changes: 2 additions & 0 deletions scripts/cli/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
playground.yaml
playground.json
Binary file modified scripts/cli/general.json.gz
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# Render shell-script-command-completion

Render shell-script-command-completion

## Usage

```bash
$ bashly render templates/shell-script-command-completion .
```

Large diffs are not rendered by default.

11 changes: 11 additions & 0 deletions scripts/cli/templates/shell-script-command-completion/main.gtx
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# https://github.com/DannyBen/bashly/blob/master/lib/bashly/script/command.rb
# https://www.rubydoc.info/gems/gtx

> name: {{ full_name }}
> description: {{ help.sanitize_for_print }}
> usage: {{ usage_string.sanitize_for_print }}
> options: []
> inheritedOptions:
> subcommands:


Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
cd /Users/vsaboulin/Documents/github/kafka-docker-playground/scripts/cli

bashly render templates/shell-script-command-completion .
yq -o=json playground.yaml > playground.json

{ printf "["; cat playground.json | jq -c; cat templates/shell-script-command-completion/general_end.json; } > general.json
gzip -f general.json
cd -
20 changes: 20 additions & 0 deletions scripts/cli/templates/shell-script-command-completion/render.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# render script - shell-script-command-completion
require 'gtx'

# Load the GTX template
template = "#{source}/main.gtx"
gtx = GTX.load_file template

File.open("#{target}/playground.yaml", "w") do |file|
file.write(gtx.parse(command))
end

template = "#{source}/subcommand.gtx"
gtx = GTX.load_file template

# Append to a file for each subcommand
command.deep_commands.reject(&:private).each do |subcommand|
File.open("#{target}/playground.yaml", "a") do |file|
file.write(gtx.parse(subcommand))
end
end
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
> - name: {{ name }}
> description: {{ help.sanitize_for_print }}
> usage: {{ usage_string.sanitize_for_print }}
> options:
if flags.any?
flags.each do |flag|
> - names:
> - {{ flag.name }}
> argument: ""
> description: {{ flag.help.gsub("\n", '. ').gsub(":", ' ') }}
end
end

0 comments on commit 4c04b67

Please sign in to comment.