2017-07-15 04:24:31 +00:00
2018-03-16 18:11:08 +00:00
using namespace System . Management . Automation
using namespace System . Management . Automation . Language
2018-10-18 20:50:06 +00:00
Register-ArgumentCompleter -Native -CommandName 'zola' -ScriptBlock {
2018-03-16 18:11:08 +00:00
param ( $wordToComplete , $commandAst , $cursorPosition )
$commandElements = $commandAst . CommandElements
$command = @ (
2018-10-18 20:50:06 +00:00
'zola'
2018-03-16 18:11:08 +00:00
for ( $i = 1 ; $i -lt $commandElements . Count ; $i + + ) {
$element = $commandElements [ $i ]
if ( $element -isnot [ StringConstantExpressionAst ] -or
$element . StringConstantType -ne [ StringConstantType ] :: BareWord -or
$element . Value . StartsWith ( '-' ) ) {
break
}
$element . Value
} ) -join ';'
$completions = @ ( switch ( $command ) {
2018-10-18 20:50:06 +00:00
'zola' {
2020-05-23 09:55:45 +00:00
[ CompletionResult ] :: new ( '-c' , 'c' , [ CompletionResultType ] :: ParameterName , 'Path to a config file other than config.toml in the root of project' )
[ CompletionResult ] :: new ( '--config' , 'config' , [ CompletionResultType ] :: ParameterName , 'Path to a config file other than config.toml in the root of project' )
2018-03-16 18:11:08 +00:00
[ CompletionResult ] :: new ( '-h' , 'h' , [ CompletionResultType ] :: ParameterName , 'Prints help information' )
[ CompletionResult ] :: new ( '--help' , 'help' , [ CompletionResultType ] :: ParameterName , 'Prints help information' )
[ CompletionResult ] :: new ( '-V' , 'V' , [ CompletionResultType ] :: ParameterName , 'Prints version information' )
[ CompletionResult ] :: new ( '--version' , 'version' , [ CompletionResultType ] :: ParameterName , 'Prints version information' )
2018-10-18 20:50:06 +00:00
[ CompletionResult ] :: new ( 'init' , 'init' , [ CompletionResultType ] :: ParameterValue , 'Create a new Zola project' )
2019-06-21 07:04:05 +00:00
[ CompletionResult ] :: new ( 'build' , 'build' , [ CompletionResultType ] :: ParameterValue , 'Deletes the output directory if there is one and builds the site' )
2018-03-16 18:11:08 +00:00
[ CompletionResult ] :: new ( 'serve' , 'serve' , [ CompletionResultType ] :: ParameterValue , 'Serve the site. Rebuild and reload on change automatically' )
2019-06-21 07:04:05 +00:00
[ CompletionResult ] :: new ( 'check' , 'check' , [ CompletionResultType ] :: ParameterValue , 'Try building the project without rendering it. Checks links' )
2018-03-16 18:11:08 +00:00
[ CompletionResult ] :: new ( 'help' , 'help' , [ CompletionResultType ] :: ParameterValue , 'Prints this message or the help of the given subcommand(s)' )
break
}
2018-10-18 20:50:06 +00:00
'zola;init' {
2018-03-16 18:11:08 +00:00
[ CompletionResult ] :: new ( '-h' , 'h' , [ CompletionResultType ] :: ParameterName , 'Prints help information' )
[ CompletionResult ] :: new ( '--help' , 'help' , [ CompletionResultType ] :: ParameterName , 'Prints help information' )
[ CompletionResult ] :: new ( '-V' , 'V' , [ CompletionResultType ] :: ParameterName , 'Prints version information' )
[ CompletionResult ] :: new ( '--version' , 'version' , [ CompletionResultType ] :: ParameterName , 'Prints version information' )
break
}
2018-10-18 20:50:06 +00:00
'zola;build' {
2018-03-16 18:11:08 +00:00
[ CompletionResult ] :: new ( '-u' , 'u' , [ CompletionResultType ] :: ParameterName , 'Force the base URL to be that value (default to the one in config.toml)' )
[ CompletionResult ] :: new ( '--base-url' , 'base-url' , [ CompletionResultType ] :: ParameterName , 'Force the base URL to be that value (default to the one in config.toml)' )
[ CompletionResult ] :: new ( '-o' , 'o' , [ CompletionResultType ] :: ParameterName , 'Outputs the generated site in the given path' )
[ CompletionResult ] :: new ( '--output-dir' , 'output-dir' , [ CompletionResultType ] :: ParameterName , 'Outputs the generated site in the given path' )
2019-08-25 17:15:12 +00:00
[ CompletionResult ] :: new ( '--drafts' , 'drafts' , [ CompletionResultType ] :: ParameterName , 'Include drafts when loading the site' )
2018-03-16 18:11:08 +00:00
[ CompletionResult ] :: new ( '-h' , 'h' , [ CompletionResultType ] :: ParameterName , 'Prints help information' )
[ CompletionResult ] :: new ( '--help' , 'help' , [ CompletionResultType ] :: ParameterName , 'Prints help information' )
[ CompletionResult ] :: new ( '-V' , 'V' , [ CompletionResultType ] :: ParameterName , 'Prints version information' )
[ CompletionResult ] :: new ( '--version' , 'version' , [ CompletionResultType ] :: ParameterName , 'Prints version information' )
break
}
2018-10-18 20:50:06 +00:00
'zola;serve' {
2018-03-16 18:11:08 +00:00
[ CompletionResult ] :: new ( '-i' , 'i' , [ CompletionResultType ] :: ParameterName , 'Interface to bind on' )
[ CompletionResult ] :: new ( '--interface' , 'interface' , [ CompletionResultType ] :: ParameterName , 'Interface to bind on' )
[ CompletionResult ] :: new ( '-p' , 'p' , [ CompletionResultType ] :: ParameterName , 'Which port to use' )
[ CompletionResult ] :: new ( '--port' , 'port' , [ CompletionResultType ] :: ParameterName , 'Which port to use' )
[ CompletionResult ] :: new ( '-o' , 'o' , [ CompletionResultType ] :: ParameterName , 'Outputs the generated site in the given path' )
[ CompletionResult ] :: new ( '--output-dir' , 'output-dir' , [ CompletionResultType ] :: ParameterName , 'Outputs the generated site in the given path' )
[ CompletionResult ] :: new ( '-u' , 'u' , [ CompletionResultType ] :: ParameterName , 'Changes the base_url' )
[ CompletionResult ] :: new ( '--base-url' , 'base-url' , [ CompletionResultType ] :: ParameterName , 'Changes the base_url' )
2018-11-12 20:37:26 +00:00
[ CompletionResult ] :: new ( '--watch-only' , 'watch-only' , [ CompletionResultType ] :: ParameterName , 'Do not start a server, just re-build project on changes' )
2019-08-25 17:15:12 +00:00
[ CompletionResult ] :: new ( '--drafts' , 'drafts' , [ CompletionResultType ] :: ParameterName , 'Include drafts when loading the site' )
[ CompletionResult ] :: new ( '-O' , 'O' , [ CompletionResultType ] :: ParameterName , 'Open site in the default browser' )
[ CompletionResult ] :: new ( '--open' , 'open' , [ CompletionResultType ] :: ParameterName , 'Open site in the default browser' )
2018-03-16 18:11:08 +00:00
[ CompletionResult ] :: new ( '-h' , 'h' , [ CompletionResultType ] :: ParameterName , 'Prints help information' )
[ CompletionResult ] :: new ( '--help' , 'help' , [ CompletionResultType ] :: ParameterName , 'Prints help information' )
2019-06-21 07:04:05 +00:00
[ CompletionResult ] :: new ( '-V' , 'V' , [ CompletionResultType ] :: ParameterName , 'Prints version information' )
[ CompletionResult ] :: new ( '--version' , 'version' , [ CompletionResultType ] :: ParameterName , 'Prints version information' )
break
}
'zola;check' {
2019-08-25 17:15:12 +00:00
[ CompletionResult ] :: new ( '--drafts' , 'drafts' , [ CompletionResultType ] :: ParameterName , 'Include drafts when loading the site' )
2019-06-21 07:04:05 +00:00
[ CompletionResult ] :: new ( '-h' , 'h' , [ CompletionResultType ] :: ParameterName , 'Prints help information' )
[ CompletionResult ] :: new ( '--help' , 'help' , [ CompletionResultType ] :: ParameterName , 'Prints help information' )
2018-03-16 18:11:08 +00:00
[ CompletionResult ] :: new ( '-V' , 'V' , [ CompletionResultType ] :: ParameterName , 'Prints version information' )
[ CompletionResult ] :: new ( '--version' , 'version' , [ CompletionResultType ] :: ParameterName , 'Prints version information' )
break
}
2018-10-18 20:50:06 +00:00
'zola;help' {
2018-03-16 18:11:08 +00:00
[ CompletionResult ] :: new ( '-h' , 'h' , [ CompletionResultType ] :: ParameterName , 'Prints help information' )
[ CompletionResult ] :: new ( '--help' , 'help' , [ CompletionResultType ] :: ParameterName , 'Prints help information' )
[ CompletionResult ] :: new ( '-V' , 'V' , [ CompletionResultType ] :: ParameterName , 'Prints version information' )
[ CompletionResult ] :: new ( '--version' , 'version' , [ CompletionResultType ] :: ParameterName , 'Prints version information' )
break
2017-07-15 04:24:31 +00:00
}
2018-03-16 18:11:08 +00:00
} )
2017-07-15 04:24:31 +00:00
2018-03-16 18:11:08 +00:00
$completions . Where { $_ . CompletionText -like " $wordToComplete * " } |
Sort-Object -Property ListItemText
2017-07-15 04:24:31 +00:00
}