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.

89 lines
6.7KB

  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('-h', 'h', [CompletionResultType]::ParameterName, 'Prints help information')
  45. [CompletionResult]::new('--help', 'help', [CompletionResultType]::ParameterName, 'Prints help information')
  46. [CompletionResult]::new('-V', 'V', [CompletionResultType]::ParameterName, 'Prints version information')
  47. [CompletionResult]::new('--version', 'version', [CompletionResultType]::ParameterName, 'Prints version information')
  48. break
  49. }
  50. 'zola;serve' {
  51. [CompletionResult]::new('-i', 'i', [CompletionResultType]::ParameterName, 'Interface to bind on')
  52. [CompletionResult]::new('--interface', 'interface', [CompletionResultType]::ParameterName, 'Interface to bind on')
  53. [CompletionResult]::new('-p', 'p', [CompletionResultType]::ParameterName, 'Which port to use')
  54. [CompletionResult]::new('--port', 'port', [CompletionResultType]::ParameterName, 'Which port to use')
  55. [CompletionResult]::new('-o', 'o', [CompletionResultType]::ParameterName, 'Outputs the generated site in the given path')
  56. [CompletionResult]::new('--output-dir', 'output-dir', [CompletionResultType]::ParameterName, 'Outputs the generated site in the given path')
  57. [CompletionResult]::new('-u', 'u', [CompletionResultType]::ParameterName, 'Changes the base_url')
  58. [CompletionResult]::new('--base-url', 'base-url', [CompletionResultType]::ParameterName, 'Changes the base_url')
  59. [CompletionResult]::new('--watch-only', 'watch-only', [CompletionResultType]::ParameterName, 'Do not start a server, just re-build project on changes')
  60. [CompletionResult]::new('-h', 'h', [CompletionResultType]::ParameterName, 'Prints help information')
  61. [CompletionResult]::new('--help', 'help', [CompletionResultType]::ParameterName, 'Prints help information')
  62. [CompletionResult]::new('-V', 'V', [CompletionResultType]::ParameterName, 'Prints version information')
  63. [CompletionResult]::new('--version', 'version', [CompletionResultType]::ParameterName, 'Prints version information')
  64. break
  65. }
  66. 'zola;check' {
  67. [CompletionResult]::new('-h', 'h', [CompletionResultType]::ParameterName, 'Prints help information')
  68. [CompletionResult]::new('--help', 'help', [CompletionResultType]::ParameterName, 'Prints help information')
  69. [CompletionResult]::new('-V', 'V', [CompletionResultType]::ParameterName, 'Prints version information')
  70. [CompletionResult]::new('--version', 'version', [CompletionResultType]::ParameterName, 'Prints version information')
  71. break
  72. }
  73. 'zola;help' {
  74. [CompletionResult]::new('-h', 'h', [CompletionResultType]::ParameterName, 'Prints help information')
  75. [CompletionResult]::new('--help', 'help', [CompletionResultType]::ParameterName, 'Prints help information')
  76. [CompletionResult]::new('-V', 'V', [CompletionResultType]::ParameterName, 'Prints version information')
  77. [CompletionResult]::new('--version', 'version', [CompletionResultType]::ParameterName, 'Prints version information')
  78. break
  79. }
  80. })
  81. $completions.Where{ $_.CompletionText -like "$wordToComplete*" } |
  82. Sort-Object -Property ListItemText
  83. }