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.

75 lines
2.0KB

  1. @('gutenberg', './gutenberg') | %{
  2. Register-ArgumentCompleter -Native -CommandName $_ -ScriptBlock {
  3. param($wordToComplete, $commandAst, $cursorPosition)
  4. $command = '_gutenberg'
  5. $commandAst.CommandElements |
  6. Select-Object -Skip 1 |
  7. %{
  8. switch ($_.ToString()) {
  9. 'gutenberg' {
  10. $command += '_gutenberg'
  11. break
  12. }
  13. 'init' {
  14. $command += '_init'
  15. break
  16. }
  17. 'build' {
  18. $command += '_build'
  19. break
  20. }
  21. 'serve' {
  22. $command += '_serve'
  23. break
  24. }
  25. 'help' {
  26. $command += '_help'
  27. break
  28. }
  29. default {
  30. break
  31. }
  32. }
  33. }
  34. $completions = @()
  35. switch ($command) {
  36. '_gutenberg' {
  37. $completions = @('init', 'build', 'serve', 'help', '-c', '-h', '-V', '--config', '--help', '--version')
  38. }
  39. '_gutenberg_init' {
  40. $completions = @('-h', '-V', '--help', '--version')
  41. }
  42. '_gutenberg_build' {
  43. $completions = @('-h', '-V', '-u', '--help', '--version', '--base-url')
  44. }
  45. '_gutenberg_serve' {
  46. $completions = @('-h', '-V', '-i', '-p', '--help', '--version', '--interface', '--port')
  47. }
  48. '_gutenberg_help' {
  49. $completions = @('-h', '-V', '--help', '--version')
  50. }
  51. }
  52. $completions |
  53. ?{ $_ -like "$wordToComplete*" } |
  54. Sort-Object |
  55. %{ New-Object System.Management.Automation.CompletionResult $_, $_, 'ParameterValue', $_ }
  56. }
  57. }