#compdef xclogparser
local context state state_descr line
_xclogparser_commandname=$words[1]
typeset -A opt_args

_xclogparser() {
    integer ret=1
    local -a args
    args+=(
        '(-h --help)'{-h,--help}'[Show help information.]'
        '(-): :->command'
        '(-)*:: :->arg'
    )
    _arguments -w -s -S $args[@] && ret=0
    case $state in
        (command)
            local subcommands
            subcommands=(
                'parse:Parses the content of an xcactivitylog file'
                'dump:Dumps the xcactivitylog file into a JSON document'
                'manifest:Shows the content of a LogManifest plist file as a JSON document.'
                'version:Displays the version of the tool.'
                'help:Show subcommand help information.'
            )
            _describe "subcommand" subcommands
            ;;
        (arg)
            case ${words[1]} in
                (parse)
                    _xclogparser_parse
                    ;;
                (dump)
                    _xclogparser_dump
                    ;;
                (manifest)
                    _xclogparser_manifest
                    ;;
                (version)
                    _xclogparser_version
                    ;;
                (help)
                    _xclogparser_help
                    ;;
            esac
            ;;
    esac

    return ret
}

_xclogparser_parse() {
    integer ret=1
    local -a args
    args+=(
        '--file[The path to a .xcactivitylog file.]:file:'
        '--derived_data[The path to the DerivedData directory.
        Use it if it'"'"'s not the default ~/Library/Developer/Xcode/DerivedData/.]:derived_data:'
        '--project[The name of an Xcode project. The tool will try to find the latest log folder
        with this prefix in the DerivedData directory. Use with `--strictProjectName`
        for stricter name matching.]:project:'
        '--workspace[The path to the .xcworkspace folder. Used to find the Derived Data project directory
        if no `--project` flag is present.]:workspace:'
        '--xcodeproj[The path to the .xcodeproj folder. Used to find the Derived Data project directory
        if no `--project` and no `--workspace` flag is present.]:xcodeproj:'
        '--reporter[Mandatory. The reporter to use. It could be `json`, `flatJson`, `summaryJson`,
        `chromeTracer`, `html` or `btr`]:reporter:'
        '--machine_name[Optional. The name of the machine. If not specified, the host name will be used.]:machine_name:'
        '--redacted[Redacts the username of the paths found in the log.
        For instance, /Users/timcook/project will be /Users/<redacted>/project]'
        '--without_build_specific_information[Removes build specific information from the logs.
        For instance, DerivedData/Product-bolnckhlbzxpxoeyfujluasoupft/Build
        will be DerivedData/Product/Build]'
        '--strictProjectName[Use strict name testing when trying to find the latest version of the project
        in the DerivedData directory.]'
        '--output[Optional. Path to which the report will be written to. If not specified,
        the report will be written to the standard output.]:output:'
        '--rootOutput[Optional. Add the project output into the given current path,
        example: myGivenPath/report.json.]:rootOutput:'
        '--omit_warnings[If present, the report will omit the Warnings found in the log.
        Useful to reduce the size of the final report.]'
        '--omit_notes[If present, the report will omit the Notes found in the log.
        Useful to reduce the size of the final report.]'
        '--trunc_large_issues[If present, for tasks with more than a 100 issues (warnings, notes or errors)
        Those will be truncated to a 100.
        Useful to reduce the amount of memory used and the size of the report.]'
        '(-h --help)'{-h,--help}'[Show help information.]'
    )
    _arguments -w -s -S $args[@] && ret=0

    return ret
}

_xclogparser_dump() {
    integer ret=1
    local -a args
    args+=(
        '--file[The path to a .xcactivitylog file.]:file:'
        '--derived_data[The path to the DerivedData directory.
        Use it if it'"'"'s not the default ~/Library/Developer/Xcode/DerivedData/.]:derived_data:'
        '--project[The name of an Xcode project. The tool will try to find the latest log folder
        with this prefix in the DerivedData directory. Use with `--strictProjectName`
        for stricter name matching.]:project:'
        '--workspace[The path to the .xcworkspace folder. Used to find the Derived Data project directory
        if no `--project` flag is present.]:workspace:'
        '--xcodeproj[The path to the .xcodeproj folder. Used to find the Derived Data project directory
        if no `--project` and no `--workspace` flag is present.]:xcodeproj:'
        '--redacted[Redacts the username of the paths found in the log.
        For instance, /Users/timcook/project will be /Users/<redacted>/project]'
        '--without_build_specific_information[Removes build specific information from the logs.
        For instance, DerivedData/Product-bolnckhlbzxpxoeyfujluasoupft/Build
        will be DerivedData/Product/Build]'
        '--strictProjectName[Use strict name testing when trying to find the latest version of the project
        in the DerivedData directory.]'
        '--output[Optional. Path to which the report will be written to. If not specified,
        the report will be written to the standard output.]:output:'
        '(-h --help)'{-h,--help}'[Show help information.]'
    )
    _arguments -w -s -S $args[@] && ret=0

    return ret
}

_xclogparser_manifest() {
    integer ret=1
    local -a args
    args+=(
        '--long_manifest[The path to an existing LogStoreManifest.plist.]:long_manifest:'
        '--derived_data[The path to the DerivedData directory.
        Use it if it'"'"'s not the default ~/Library/Developer/Xcode/DerivedData/.]:derived_data:'
        '--project[The name of an Xcode project. The tool will try to find the latest log folder
        with this prefix in the DerivedData directory. Use with `--strictProjectName`
        for stricter name matching.]:project:'
        '--workspace[The path to the .xcworkspace folder. Used to find the Derived Data project directory
        if no `--project` flag is present.]:workspace:'
        '--xcodeproj[The path to the .xcodeproj folder. Used to find the Derived Data project directory
        if no `--project` and no `--workspace` flag is present.]:xcodeproj:'
        '--strictProjectName[Use strict name testing when trying to find the latest version of the project
        in the DerivedData directory.]'
        '--output[Optional. Path to which the report will be written to. If not specified,
        the report will be written to the standard output.]:output:'
        '(-h --help)'{-h,--help}'[Show help information.]'
    )
    _arguments -w -s -S $args[@] && ret=0

    return ret
}

_xclogparser_version() {
    integer ret=1
    local -a args
    args+=(
        '(-h --help)'{-h,--help}'[Show help information.]'
    )
    _arguments -w -s -S $args[@] && ret=0

    return ret
}

_xclogparser_help() {
    integer ret=1
    local -a args
    args+=(
        ':subcommands:'
    )
    _arguments -w -s -S $args[@] && ret=0

    return ret
}


_custom_completion() {
    local completions=("${(@f)$($*)}")
    _describe '' completions
}

_xclogparser
