You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

94 lines
7.3KB

  1. using namespace System.Management.Automation
  2. using namespace System.Management.Automation.Language
  3. Register-ArgumentCompleter -Native -CommandName 'zola' -ScriptBlock {
  4. param($wordToComplete, $commandAst, $cursorPosition)
  5. $commandElements = $commandAst.CommandElements
  6. $command = @(
  7. 'zola'
  8. for ($i = 1; $i -lt $commandElements.Count; $i++) {
  9. $element = $commandElements[$i]
  10. if ($element -isnot [StringConstantExpressionAst] -or
  11. $element.StringConstantType -ne [StringConstantType]::BareWord -or
  12. $element.Value.StartsWith('-')) {
  13. break
  14. }
  15. $element.Value
  16. }) -join ';'
  17. $completions = @(switch ($command) {
  18. 'zola' {
  19. [CompletionResult]::new('-c', 'c', [CompletionResultType]::ParameterName, 'Path to a config file other than config.toml')
  20. [CompletionResult]::new('--config', 'config', [CompletionResultType]::ParameterName, 'Path to a config file other than config.toml')
  21. [CompletionResult]::new('-h', 'h', [CompletionResultType]::ParameterName, 'Prints help information')
  22. [CompletionResult]::new('--help', 'help', [CompletionResultType]::ParameterName, 'Prints help information')
  23. [CompletionResult]::new('-V', 'V', [CompletionResultType]::ParameterName, 'Prints version information')
  24. [CompletionResult]::new('--version', 'version', [CompletionResultType]::ParameterName, 'Prints version information')
  25. [CompletionResult]::new('init', 'init', [CompletionResultType]::ParameterValue, 'Create a new Zola project')
  26. [CompletionResult]::new('build', 'build', [CompletionResultType]::ParameterValue, 'Deletes the output directory if there is one and builds the site')
  27. [CompletionResult]::new('serve', 'serve', [CompletionResultType]::ParameterValue, 'Serve the site. Rebuild and reload on change automatically')
  28. [CompletionResult]::new('check', 'check', [CompletionResultType]::ParameterValue, 'Try building the project without rendering it. Checks links')
  29. [CompletionResult]::new('help', 'help', [CompletionResultType]::ParameterValue, 'Prints this message or the help of the given subcommand(s)')
  30. break
  31. }
  32. 'zola;init' {
  33. [CompletionResult]::new('-h', 'h', [CompletionResultType]::ParameterName, 'Prints help information')
  34. [CompletionResult]::new('--help', 'help', [CompletionResultType]::ParameterName, 'Prints help information')
  35. [CompletionResult]::new('-V', 'V', [CompletionResultType]::ParameterName, 'Prints version information')
  36. [CompletionResult]::new('--version', 'version', [CompletionResultType]::ParameterName, 'Prints version information')
  37. break
  38. }
  39. 'zola;build' {
  40. [CompletionResult]::new('-u', 'u', [CompletionResultType]::ParameterName, 'Force the base URL to be that value (default to the one in config.toml)')
  41. [CompletionResult]::new('--base-url', 'base-url', [CompletionResultType]::ParameterName, 'Force the base URL to be that value (default to the one in config.toml)')
  42. [CompletionResult]::new('-o', 'o', [CompletionResultType]::ParameterName, 'Outputs the generated site in the given path')
  43. [CompletionResult]::new('--output-dir', 'output-dir', [CompletionResultType]::ParameterName, 'Outputs the generated site in the given path')
  44. [CompletionResult]::new('--drafts', 'drafts', [CompletionResultType]::ParameterName, 'Include drafts when loading the site')
  45. [CompletionResult]::new('-h', 'h', [CompletionResultType]::ParameterName, 'Prints help information')
  46. [CompletionResult]::new('--help', 'help', [CompletionResultType]::ParameterName, 'Prints help information')
  47. [CompletionResult]::new('-V', 'V', [CompletionResultType]::ParameterName, 'Prints version information')
  48. [CompletionResult]::new('--version', 'version', [CompletionResultType]::ParameterName, 'Prints version information')
  49. break
  50. }
  51. 'zola;serve' {
  52. [CompletionResult]::new('-i', 'i', [CompletionResultType]::ParameterName, 'Interface to bind on')
  53. [CompletionResult]::new('--interface', 'interface', [CompletionResultType]::ParameterName, 'Interface to bind on')
  54. [CompletionResult]::new('-p', 'p', [CompletionResultType]::ParameterName, 'Which port to use')
  55. [CompletionResult]::new('--port', 'port', [CompletionResultType]::ParameterName, 'Which port to use')
  56. [CompletionResult]::new('-o', 'o', [CompletionResultType]::ParameterName, 'Outputs the generated site in the given path')
  57. [CompletionResult]::new('--output-dir', 'output-dir', [CompletionResultType]::ParameterName, 'Outputs the generated site in the given path')
  58. [CompletionResult]::new('-u', 'u', [CompletionResultType]::ParameterName, 'Changes the base_url')
  59. [CompletionResult]::new('--base-url', 'base-url', [CompletionResultType]::ParameterName, 'Changes the base_url')
  60. [CompletionResult]::new('--watch-only', 'watch-only', [CompletionResultType]::ParameterName, 'Do not start a server, just re-build project on changes')
  61. [CompletionResult]::new('--drafts', 'drafts', [CompletionResultType]::ParameterName, 'Include drafts when loading the site')
  62. [CompletionResult]::new('-O', 'O', [CompletionResultType]::ParameterName, 'Open site in the default browser')
  63. [CompletionResult]::new('--open', 'open', [CompletionResultType]::ParameterName, 'Open site in the default browser')
  64. [CompletionResult]::new('-h', 'h', [CompletionResultType]::ParameterName, 'Prints help information')
  65. [CompletionResult]::new('--help', 'help', [CompletionResultType]::ParameterName, 'Prints help information')
  66. [CompletionResult]::new('-V', 'V', [CompletionResultType]::ParameterName, 'Prints version information')
  67. [CompletionResult]::new('--version', 'version', [CompletionResultType]::ParameterName, 'Prints version information')
  68. break
  69. }
  70. 'zola;check' {
  71. [CompletionResult]::new('--drafts', 'drafts', [CompletionResultType]::ParameterName, 'Include drafts when loading the site')
  72. [CompletionResult]::new('-h', 'h', [CompletionResultType]::ParameterName, 'Prints help information')
  73. [CompletionResult]::new('--help', 'help', [CompletionResultType]::ParameterName, 'Prints help information')
  74. [CompletionResult]::new('-V', 'V', [CompletionResultType]::ParameterName, 'Prints version information')
  75. [CompletionResult]::new('--version', 'version', [CompletionResultType]::ParameterName, 'Prints version information')
  76. break
  77. }
  78. 'zola;help' {
  79. [CompletionResult]::new('-h', 'h', [CompletionResultType]::ParameterName, 'Prints help information')
  80. [CompletionResult]::new('--help', 'help', [CompletionResultType]::ParameterName, 'Prints help information')
  81. [CompletionResult]::new('-V', 'V', [CompletionResultType]::ParameterName, 'Prints version information')
  82. [CompletionResult]::new('--version', 'version', [CompletionResultType]::ParameterName, 'Prints version information')
  83. break
  84. }
  85. })
  86. $completions.Where{ $_.CompletionText -like "$wordToComplete*" } |
  87. Sort-Object -Property ListItemText
  88. }