Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
132 changes: 0 additions & 132 deletions custom-completions/auto-generate/parse-fish.nu

This file was deleted.

79 changes: 0 additions & 79 deletions custom-completions/auto-generate/parse-help.nu

This file was deleted.

62 changes: 2 additions & 60 deletions custom-completions/winget/winget-completions.nu
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ export extern "winget install" [
]
export alias "winget add" = winget install

export def "winget show" [
export extern "winget show" [
pos_query?: string,
--query(-q): string, # The query used to search for a package
--id: string, # Filter results by id
Expand All @@ -189,66 +189,8 @@ export def "winget show" [
--accept_package_agreements, # Accept all licence agreements for packages
--header: string, # Optional Windows-Package-Manager REST source HTTP header
--accept_source_agreements, # Accept all source agreements during source operations
--raw, # Output the raw CLI output instead of structured data
--help(-?), # Display the help for this command
] {
let flagify = { |name, value| nu-complete winget flagify $name $value }

def sanitize-line []: string -> string {
let it = $in
let parsed = ($it | parse '{name}:{value}')
if ($parsed | is-empty) { return $"($it)" }
let parsed = ($parsed | first)
try {
$"($parsed.name):(if ($parsed.value | str trim | is-empty) { '' } else { $"(char space)(char dq)($parsed.value | str trim)(char dq)" })"
} catch {
$"($it)"
}
}

let params = ([
"show"
] | append ([
$pos_query
(do $flagify query $query)
(do $flagify id $id)
(do $flagify name $name)
(do $flagify moniker $moniker)
(do $flagify version $version)
(do $flagify source $source)
#(do $flagify scope $scope)
(do $flagify exact $exact)
(do $flagify interactive $interactive)
(do $flagify silent $silent)
(do $flagify locale $locale)
(do $flagify log $log)
(do $flagify override $override)
(do $flagify location $location)
(do $flagify force $force)
(do $flagify accept_package_agreements $accept_package_agreements)
(do $flagify header $header)
(do $flagify accept_source_agreements $accept_source_agreements)
(do $flagify help $help)
] | flatten) | filter { not ($in | is-empty)})

let output = ^winget ...$params
if $raw or $help or ($output | str contains "No package selection argument was provided") {
$output
} else {
let lines = ($output | lines)

if ($lines | first) =~ "Multiple packages found matching input criteria." {
$"(ansi yellow)($lines | first | str trim)(ansi reset)"
nu-complete winget parse table ($lines | skip 1) | select name id source
} else if ($lines | first) =~ "No package found matching input criteria." {
$"(ansi yellow)($lines | first | str trim)(ansi reset)"
} else {
let header = ($lines | first | parse -r 'Found (?P<Name>.+) \[(?P<Id>.+)\]')
let manifest = ($lines | skip | each { sanitize-line } | str join (char newline) | from yaml)
$header | first | merge $manifest
}
}
}
]
export alias "winget view" = winget show

# Manage sources of packages
Expand Down
50 changes: 28 additions & 22 deletions needs-update/custom-completions/auto-generate/README.md
Original file line number Diff line number Diff line change
@@ -1,56 +1,61 @@
# auto-generate completions

- basic helpers to parse --help information from cli commands and export nu completions source
- basic helpers tp parse .fish complete files and export nu completions source
- basic helpers to parse `--help` information from cli commands and export nu completions source
- basic helpers to parse `.fish` complete files and export nu completions source

# parse-fish
## parse-fish

### current

## current
- only parses out simple complete's with no complete's boolean arguments like -f
- does not map fish autocomplete helpers to nu-complete helps (a nu library of autocomplete utils would be neat)

## usage
### usage

be in a directory with one or more .fish completion scripts
be in a directory with one or more `.fish` completion scripts

A good one is
A good one is

`git clone https://github.com/fish-shell/fish-shell`
`cd fish-shell/share/completions`
```nushell
git clone https://github.com/fish-shell/fish-shell
cd fish-shell/share/completions
```

To build all .fish files in the current directory `build-completions-from-pwd`
To build all `.fish` files in the current directory `build-completions-from-pwd`

```nu
```nushell
build-completions-from-pwd
ls *.nu
```

To build a single .fish file and choose the output file
```nu
To build a single `.fish` file and choose the output file

```nushell
build-completion cargo.fish cargo.nu
```
# parse-help

## current limitations
## parse-help

### current limitations

- Only flags are parsed, arguments are not parsed and ...args is injected at the end to catch all
- Only flags are parsed, arguments are not parsed and `...args` is injected at the end to catch all
- Some examples of `--flags` in descriptions can throw off the regex and get included in the parsed flags
- `<format>` (types) to flags are parsed, but not added to the nu shell completion type hints

## usage
### usage

generate and save source to a file

```nu
```nushell
source parse-help.nu
cargo --help | parse-help | make-completion cargo | save cargo.nu
```

## example
### example

This can be saved to a file and sourced. Example of output

```nu
```nushell
extern "cargo" [
--version(-V) #Print version info and exit
--list #List installed commands
Expand Down Expand Up @@ -84,7 +89,8 @@ extern "nu" [
```

Which outputs like so on tab completion for `cargo --`
```

```nushell
❯ | cargo --
--color Coloring: auto, always, never
--config Override a configuration value (unstable)
Expand All @@ -98,4 +104,4 @@ Which outputs like so on tab completion for `cargo --`
--quiet Do not print cargo log messages
--verbose Use verbose output (-vv very verbose/build.rs output)
--version Print version info and exit
```
```
Loading