neomake 0.4.2

Yet another task runner as make alternative, inspired by GitLab pipelines.

using namespace System.Management.Automation
using namespace System.Management.Automation.Language

Register-ArgumentCompleter -Native -CommandName 'neomake' -ScriptBlock {
    param($wordToComplete, $commandAst, $cursorPosition)

    $commandElements = $commandAst.CommandElements
    $command = @(
        'neomake'
        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('-') -or
                $element.Value -eq $wordToComplete) {
                break
        }
        $element.Value
    }) -join ';'

    $completions = @(switch ($command) {
        'neomake' {
            [CompletionResult]::new('-e', 'e', [CompletionResultType]::ParameterName, 'enables experimental features')
            [CompletionResult]::new('--experimental', 'experimental', [CompletionResultType]::ParameterName, 'enables experimental features')
            [CompletionResult]::new('-h', 'h', [CompletionResultType]::ParameterName, 'Print help')
            [CompletionResult]::new('--help', 'help', [CompletionResultType]::ParameterName, 'Print help')
            [CompletionResult]::new('-V', 'V', [CompletionResultType]::ParameterName, 'Print version')
            [CompletionResult]::new('--version', 'version', [CompletionResultType]::ParameterName, 'Print version')
            [CompletionResult]::new('man', 'man', [CompletionResultType]::ParameterValue, 'Renders the manual.')
            [CompletionResult]::new('autocomplete', 'autocomplete', [CompletionResultType]::ParameterValue, 'Renders shell completion scripts.')
            [CompletionResult]::new('init', 'init', [CompletionResultType]::ParameterValue, 'Initializes a new default configuration in the current folder.')
            [CompletionResult]::new('run', 'run', [CompletionResultType]::ParameterValue, 'Runs task chains.')
            [CompletionResult]::new('describe', 'describe', [CompletionResultType]::ParameterValue, 'Describes the execution graph for a given task chain configuration.')
            [CompletionResult]::new('list', 'list', [CompletionResultType]::ParameterValue, 'Lists all available task chains.')
            [CompletionResult]::new('help', 'help', [CompletionResultType]::ParameterValue, 'Print this message or the help of the given subcommand(s)')
            break
        }
        'neomake;man' {
            [CompletionResult]::new('-o', 'o', [CompletionResultType]::ParameterName, 'o')
            [CompletionResult]::new('--out', 'out', [CompletionResultType]::ParameterName, 'out')
            [CompletionResult]::new('-f', 'f', [CompletionResultType]::ParameterName, 'f')
            [CompletionResult]::new('--format', 'format', [CompletionResultType]::ParameterName, 'format')
            [CompletionResult]::new('-h', 'h', [CompletionResultType]::ParameterName, 'Print help')
            [CompletionResult]::new('--help', 'help', [CompletionResultType]::ParameterName, 'Print help')
            [CompletionResult]::new('-V', 'V', [CompletionResultType]::ParameterName, 'Print version')
            [CompletionResult]::new('--version', 'version', [CompletionResultType]::ParameterName, 'Print version')
            break
        }
        'neomake;autocomplete' {
            [CompletionResult]::new('-o', 'o', [CompletionResultType]::ParameterName, 'o')
            [CompletionResult]::new('--out', 'out', [CompletionResultType]::ParameterName, 'out')
            [CompletionResult]::new('-s', 's', [CompletionResultType]::ParameterName, 's')
            [CompletionResult]::new('--shell', 'shell', [CompletionResultType]::ParameterName, 'shell')
            [CompletionResult]::new('-h', 'h', [CompletionResultType]::ParameterName, 'Print help')
            [CompletionResult]::new('--help', 'help', [CompletionResultType]::ParameterName, 'Print help')
            [CompletionResult]::new('-V', 'V', [CompletionResultType]::ParameterName, 'Print version')
            [CompletionResult]::new('--version', 'version', [CompletionResultType]::ParameterName, 'Print version')
            break
        }
        'neomake;init' {
            [CompletionResult]::new('-h', 'h', [CompletionResultType]::ParameterName, 'Print help')
            [CompletionResult]::new('--help', 'help', [CompletionResultType]::ParameterName, 'Print help')
            [CompletionResult]::new('-V', 'V', [CompletionResultType]::ParameterName, 'Print version')
            [CompletionResult]::new('--version', 'version', [CompletionResultType]::ParameterName, 'Print version')
            break
        }
        'neomake;run' {
            [CompletionResult]::new('-f', 'f', [CompletionResultType]::ParameterName, 'The configuration file to use.')
            [CompletionResult]::new('--config', 'config', [CompletionResultType]::ParameterName, 'The configuration file to use.')
            [CompletionResult]::new('-c', 'c', [CompletionResultType]::ParameterName, 'Which chain to execute.')
            [CompletionResult]::new('--chain', 'chain', [CompletionResultType]::ParameterName, 'Which chain to execute.')
            [CompletionResult]::new('-a', 'a', [CompletionResultType]::ParameterName, 'An argument to the chain.')
            [CompletionResult]::new('--arg', 'arg', [CompletionResultType]::ParameterName, 'An argument to the chain.')
            [CompletionResult]::new('-w', 'w', [CompletionResultType]::ParameterName, 'Defines how many worker threads are used for tasks that can be executed in parllel.')
            [CompletionResult]::new('--workers', 'workers', [CompletionResultType]::ParameterName, 'Defines how many worker threads are used for tasks that can be executed in parllel.')
            [CompletionResult]::new('-h', 'h', [CompletionResultType]::ParameterName, 'Print help')
            [CompletionResult]::new('--help', 'help', [CompletionResultType]::ParameterName, 'Print help')
            [CompletionResult]::new('-V', 'V', [CompletionResultType]::ParameterName, 'Print version')
            [CompletionResult]::new('--version', 'version', [CompletionResultType]::ParameterName, 'Print version')
            break
        }
        'neomake;describe' {
            [CompletionResult]::new('-f', 'f', [CompletionResultType]::ParameterName, 'The configuration file to use.')
            [CompletionResult]::new('--config', 'config', [CompletionResultType]::ParameterName, 'The configuration file to use.')
            [CompletionResult]::new('-c', 'c', [CompletionResultType]::ParameterName, 'Which chain to execute.')
            [CompletionResult]::new('--chain', 'chain', [CompletionResultType]::ParameterName, 'Which chain to execute.')
            [CompletionResult]::new('-o', 'o', [CompletionResultType]::ParameterName, 'The output format.')
            [CompletionResult]::new('--output', 'output', [CompletionResultType]::ParameterName, 'The output format.')
            [CompletionResult]::new('-h', 'h', [CompletionResultType]::ParameterName, 'Print help')
            [CompletionResult]::new('--help', 'help', [CompletionResultType]::ParameterName, 'Print help')
            [CompletionResult]::new('-V', 'V', [CompletionResultType]::ParameterName, 'Print version')
            [CompletionResult]::new('--version', 'version', [CompletionResultType]::ParameterName, 'Print version')
            break
        }
        'neomake;list' {
            [CompletionResult]::new('-f', 'f', [CompletionResultType]::ParameterName, 'The configuration file to use.')
            [CompletionResult]::new('--config', 'config', [CompletionResultType]::ParameterName, 'The configuration file to use.')
            [CompletionResult]::new('-o', 'o', [CompletionResultType]::ParameterName, 'The output format.')
            [CompletionResult]::new('--output', 'output', [CompletionResultType]::ParameterName, 'The output format.')
            [CompletionResult]::new('-h', 'h', [CompletionResultType]::ParameterName, 'Print help')
            [CompletionResult]::new('--help', 'help', [CompletionResultType]::ParameterName, 'Print help')
            [CompletionResult]::new('-V', 'V', [CompletionResultType]::ParameterName, 'Print version')
            [CompletionResult]::new('--version', 'version', [CompletionResultType]::ParameterName, 'Print version')
            break
        }
        'neomake;help' {
            [CompletionResult]::new('man', 'man', [CompletionResultType]::ParameterValue, 'Renders the manual.')
            [CompletionResult]::new('autocomplete', 'autocomplete', [CompletionResultType]::ParameterValue, 'Renders shell completion scripts.')
            [CompletionResult]::new('init', 'init', [CompletionResultType]::ParameterValue, 'Initializes a new default configuration in the current folder.')
            [CompletionResult]::new('run', 'run', [CompletionResultType]::ParameterValue, 'Runs task chains.')
            [CompletionResult]::new('describe', 'describe', [CompletionResultType]::ParameterValue, 'Describes the execution graph for a given task chain configuration.')
            [CompletionResult]::new('list', 'list', [CompletionResultType]::ParameterValue, 'Lists all available task chains.')
            [CompletionResult]::new('help', 'help', [CompletionResultType]::ParameterValue, 'Print this message or the help of the given subcommand(s)')
            break
        }
        'neomake;help;man' {
            break
        }
        'neomake;help;autocomplete' {
            break
        }
        'neomake;help;init' {
            break
        }
        'neomake;help;run' {
            break
        }
        'neomake;help;describe' {
            break
        }
        'neomake;help;list' {
            break
        }
        'neomake;help;help' {
            break
        }
    })

    $completions.Where{ $_.CompletionText -like "$wordToComplete*" } |
        Sort-Object -Property ListItemText
}