Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Brew #12

Merged
merged 3 commits into from
Dec 21, 2020
Merged

Brew #12

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
7 changes: 4 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ prefix ?= /usr/local
bindir = $(prefix)/bin
binary ?= general
release_binary?=.build/release/General
completions_folder=Scripts/completions

$(binary): $(release_binary)
cp $(release_binary) $(binary)
Expand All @@ -10,9 +11,9 @@ $(release_binary):
swift build -c release --disable-sandbox

completions: $(binary)
$(binary) --generate-completion-script zsh > _general
$(binary) --generate-completion-script bash > general
$(binary) --generate-completion-script fish > general.fish
./$(binary) --generate-completion-script zsh > $(completions_folder)/_general
./$(binary) --generate-completion-script bash > $(completions_folder)/general
./$(binary) --generate-completion-script fish > $(completions_folder)/general.fish

install: build completions
mkdir -p $(bindir)
Expand Down
141 changes: 141 additions & 0 deletions Scripts/completions/_general
Original file line number Diff line number Diff line change
@@ -0,0 +1,141 @@
#compdef general
local context state state_descr line
_general_commandname=$words[1]
typeset -A opt_args

_general() {
zstyle ":completion:*" matcher-list ''
integer ret=1
local -a args
args+=(
'(-h --help)'{-h,--help}'[Print help information.]'
'(-): :->command'
'(-)*:: :->arg'
)
_arguments -w -s -S $args[@] && ret=0
case $state in
(command)
local subcommands
subcommands=(
'gen:Generates modules from templates.'
'create:Creates a new template.'
'spec:Creates a new spec.'
'list:List of available templates.'
'setup:Provides your environment with templates'
'help:Show subcommand help information.'
)
_describe "subcommand" subcommands
;;
(arg)
case ${words[1]} in
(gen)
_general_gen
;;
(create)
_general_create
;;
(spec)
_general_spec
;;
(list)
_general_list
;;
(setup)
_general_setup
;;
(help)
_general_help
;;
esac
;;
esac

return ret
}

_general_gen() {
integer ret=1
local -a args
args+=(
'(--path -p)'{--path,-p}'[The path for the project.]:path:_files -/'
'(--name -n)'{--name,-n}'[The name of the module.]:name:'
'(--template -t)'{--template,-t}'[The name of the template.]:template:{_custom_completion $_general_commandname ---completion gen -- --template $words}'
'(--output -o)'{--output,-o}'[The output for the template.]:output:_files -/'
'--target[The target to which add files.]:target:{_custom_completion $_general_commandname ---completion gen -- --target $words}'
'--test-target[The test target to which add test files.]:test-target:{_custom_completion $_general_commandname ---completion gen -- --test-target $words}'
':variables:'
'(-h --help)'{-h,--help}'[Print help information.]'
)
_arguments -w -s -S $args[@] && ret=0

return ret
}

_general_create() {
integer ret=1
local -a args
args+=(
'(--template -t)'{--template,-t}'[The name of the template.]:template:'
'(--path -p)'{--path,-p}'[The path for the template.]:path:_files -/'
'(-h --help)'{-h,--help}'[Print help information.]'
)
_arguments -w -s -S $args[@] && ret=0

return ret
}

_general_spec() {
integer ret=1
local -a args
args+=(
'(--path -p)'{--path,-p}'[The path for the template.]:path:_files -/'
'(-h --help)'{-h,--help}'[Print help information.]'
)
_arguments -w -s -S $args[@] && ret=0

return ret
}

_general_list() {
integer ret=1
local -a args
args+=(
'(-h --help)'{-h,--help}'[Print help information.]'
)
_arguments -w -s -S $args[@] && ret=0

return ret
}

_general_setup() {
integer ret=1
local -a args
args+=(
'(--repo -r)'{--repo,-r}'[Fetch templates from specified github repo. Format: "<github>\\ \[branch\]".]:repo:'
'(--global -g)'{--global,-g}'[If specified loads templates into user home directory]:global:'
'(-h --help)'{-h,--help}'[Print help information.]'
)
_arguments -w -s -S $args[@] && ret=0

return ret
}

_general_help() {
integer ret=1
local -a args
args+=(
':subcommands:'
'(-h --help)'{-h,--help}'[Print help information.]'
)
_arguments -w -s -S $args[@] && ret=0

return ret
}


_custom_completion() {
local completions=("${(@f)$($*)}")
_describe '' completions
}

_general
142 changes: 142 additions & 0 deletions Scripts/completions/general
Original file line number Diff line number Diff line change
@@ -0,0 +1,142 @@
#!/bin/bash

_general() {
cur="${COMP_WORDS[COMP_CWORD]}"
prev="${COMP_WORDS[COMP_CWORD-1]}"
COMPREPLY=()
opts="gen create spec list setup help -h --help"
if [[ $COMP_CWORD == "1" ]]; then
COMPREPLY=( $(compgen -W "$opts" -- "$cur") )
return
fi
case ${COMP_WORDS[1]} in
(gen)
_general_gen 2
return
;;
(create)
_general_create 2
return
;;
(spec)
_general_spec 2
return
;;
(list)
_general_list 2
return
;;
(setup)
_general_setup 2
return
;;
(help)
_general_help 2
return
;;
esac
COMPREPLY=( $(compgen -W "$opts" -- "$cur") )
}
_general_gen() {
opts="--path -p --name -n --template -t --output -o --target --test-target -h --help"
if [[ $COMP_CWORD == "$1" ]]; then
COMPREPLY=( $(compgen -W "$opts" -- "$cur") )
return
fi
case $prev in
--path|-p)
COMPREPLY=( $(compgen -d -- "$cur") )
return
;;
--name|-n)

return
;;
--template|-t)
COMPREPLY=( $(compgen -W "$(general ---completion gen -- --template "$COMP_WORDS")" -- "$cur") )
return
;;
--output|-o)
COMPREPLY=( $(compgen -d -- "$cur") )
return
;;
--target)
COMPREPLY=( $(compgen -W "$(general ---completion gen -- --target "$COMP_WORDS")" -- "$cur") )
return
;;
--test-target)
COMPREPLY=( $(compgen -W "$(general ---completion gen -- --test-target "$COMP_WORDS")" -- "$cur") )
return
;;
esac
COMPREPLY=( $(compgen -W "$opts" -- "$cur") )
}
_general_create() {
opts="--template -t --path -p -h --help"
if [[ $COMP_CWORD == "$1" ]]; then
COMPREPLY=( $(compgen -W "$opts" -- "$cur") )
return
fi
case $prev in
--template|-t)

return
;;
--path|-p)
COMPREPLY=( $(compgen -d -- "$cur") )
return
;;
esac
COMPREPLY=( $(compgen -W "$opts" -- "$cur") )
}
_general_spec() {
opts="--path -p -h --help"
if [[ $COMP_CWORD == "$1" ]]; then
COMPREPLY=( $(compgen -W "$opts" -- "$cur") )
return
fi
case $prev in
--path|-p)
COMPREPLY=( $(compgen -d -- "$cur") )
return
;;
esac
COMPREPLY=( $(compgen -W "$opts" -- "$cur") )
}
_general_list() {
opts="-h --help"
if [[ $COMP_CWORD == "$1" ]]; then
COMPREPLY=( $(compgen -W "$opts" -- "$cur") )
return
fi
COMPREPLY=( $(compgen -W "$opts" -- "$cur") )
}
_general_setup() {
opts="--repo -r --global -g -h --help"
if [[ $COMP_CWORD == "$1" ]]; then
COMPREPLY=( $(compgen -W "$opts" -- "$cur") )
return
fi
case $prev in
--repo|-r)

return
;;
--global|-g)

return
;;
esac
COMPREPLY=( $(compgen -W "$opts" -- "$cur") )
}
_general_help() {
opts="-h --help"
if [[ $COMP_CWORD == "$1" ]]; then
COMPREPLY=( $(compgen -W "$opts" -- "$cur") )
return
fi
COMPREPLY=( $(compgen -W "$opts" -- "$cur") )
}


complete -F _general general
41 changes: 41 additions & 0 deletions Scripts/completions/general.fish
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
function __fish_general_using_command
set cmd (commandline -opc)
if [ (count $cmd) -eq (count $argv) ]
for i in (seq (count $argv))
if [ $cmd[$i] != $argv[$i] ]
return 1
end
end
return 0
end
return 1
end
complete -c general -n '__fish_general_using_command general' -f -a 'gen' -d 'Generates modules from templates.'
complete -c general -n '__fish_general_using_command general' -f -a 'create' -d 'Creates a new template.'
complete -c general -n '__fish_general_using_command general' -f -a 'spec' -d 'Creates a new spec.'
complete -c general -n '__fish_general_using_command general' -f -a 'list' -d 'List of available templates.'
complete -c general -n '__fish_general_using_command general' -f -a 'setup' -d 'Provides your environment with templates'
complete -c general -n '__fish_general_using_command general' -f -a 'help' -d 'Show subcommand help information.'
complete -c general -n '__fish_general_using_command general gen' -f -r -l path -s p -d 'The path for the project.'
complete -c general -n '__fish_general_using_command general gen --path' -f -a '(__fish_complete_directories)'
complete -c general -n '__fish_general_using_command general gen -p' -f -a '(__fish_complete_directories)'
complete -c general -n '__fish_general_using_command general gen' -f -r -l name -s n -d 'The name of the module.'
complete -c general -n '__fish_general_using_command general gen' -f -r -l template -s t -d 'The name of the template.'
complete -c general -n '__fish_general_using_command general gen --template' -f -a '(command general ---completion gen -- --custom (commandline -opc)[1..-1])'
complete -c general -n '__fish_general_using_command general gen -t' -f -a '(command general ---completion gen -- --custom (commandline -opc)[1..-1])'
complete -c general -n '__fish_general_using_command general gen' -f -r -l output -s o -d 'The output for the template.'
complete -c general -n '__fish_general_using_command general gen --output' -f -a '(__fish_complete_directories)'
complete -c general -n '__fish_general_using_command general gen -o' -f -a '(__fish_complete_directories)'
complete -c general -n '__fish_general_using_command general gen' -f -r -l target -d 'The target to which add files.'
complete -c general -n '__fish_general_using_command general gen --target' -f -a '(command general ---completion gen -- --custom (commandline -opc)[1..-1])'
complete -c general -n '__fish_general_using_command general gen' -f -r -l test-target -d 'The test target to which add test files.'
complete -c general -n '__fish_general_using_command general gen --test-target' -f -a '(command general ---completion gen -- --custom (commandline -opc)[1..-1])'
complete -c general -n '__fish_general_using_command general create' -f -r -l template -s t -d 'The name of the template.'
complete -c general -n '__fish_general_using_command general create' -f -r -l path -s p -d 'The path for the template.'
complete -c general -n '__fish_general_using_command general create --path' -f -a '(__fish_complete_directories)'
complete -c general -n '__fish_general_using_command general create -p' -f -a '(__fish_complete_directories)'
complete -c general -n '__fish_general_using_command general spec' -f -r -l path -s p -d 'The path for the template.'
complete -c general -n '__fish_general_using_command general spec --path' -f -a '(__fish_complete_directories)'
complete -c general -n '__fish_general_using_command general spec -p' -f -a '(__fish_complete_directories)'
complete -c general -n '__fish_general_using_command general setup' -f -r -l repo -s r -d 'Fetch templates from specified github repo. Format: "<github>\ [branch]".'
complete -c general -n '__fish_general_using_command general setup' -f -r -l global -s g -d 'If specified loads templates into user home directory'