Skip to content

Commit 959c429

Browse files
authored
Fix winget-completions breaking winget show (#1090)
by dropping output parsing of non-stable unstructured output into structured output. --- winget-completions.nu defines more than custom completions: it defines parsing for `winget show`, `winget source list`, `winget search`, `winget list`. `winget show` shows different user messages and rendered manifest information. #825 reports winget show breakage for `winget show` for packages `carapace`, `Peppy.Osu!`, `flux.flux`. The source yaml (for example [rsteube.Carapace.locale.en-US.yaml][sourceyaml]) is in YAML format. The command implementation tries to parse the rendered output and transform it into yaml, but fails to do so. The logic is quite complicated and error prone, with no guarantees on `winget show` output stability in text or format. Rather than trying to this the script, it seems safer to drop parsing the output into a structure format. #825 indicates winget show has been broken for a year. If we want to support structured output from `winget show`, it would be preferable to depend on `winget show` offering a structured output option (which it currently does not offer), or at least not offer error-prone parsing as a default part of *custom completions*. Users can still parse the output themselves. Independent of this removal, users may suggest alternative less error-prone or custom-completion-breaking approaches. [sourceyaml]: https://github.com/microsoft/winget-pkgs/blob/2ec31577c47a3c9fb141a2b6ef3113333ccef00f/manifests/r/rsteube/Carapace/1.3.0/rsteube.Carapace.locale.en-US.yaml Resolves #825 BREAKING: Drops structured output from `winget show`
1 parent bb19fdd commit 959c429

File tree

1 file changed

+2
-60
lines changed

1 file changed

+2
-60
lines changed

custom-completions/winget/winget-completions.nu

Lines changed: 2 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -169,7 +169,7 @@ export extern "winget install" [
169169
]
170170
export alias "winget add" = winget install
171171

172-
export def "winget show" [
172+
export extern "winget show" [
173173
pos_query?: string,
174174
--query(-q): string, # The query used to search for a package
175175
--id: string, # Filter results by id
@@ -189,66 +189,8 @@ export def "winget show" [
189189
--accept_package_agreements, # Accept all licence agreements for packages
190190
--header: string, # Optional Windows-Package-Manager REST source HTTP header
191191
--accept_source_agreements, # Accept all source agreements during source operations
192-
--raw, # Output the raw CLI output instead of structured data
193192
--help(-?), # Display the help for this command
194-
] {
195-
let flagify = { |name, value| nu-complete winget flagify $name $value }
196-
197-
def sanitize-line []: string -> string {
198-
let it = $in
199-
let parsed = ($it | parse '{name}:{value}')
200-
if ($parsed | is-empty) { return $"($it)" }
201-
let parsed = ($parsed | first)
202-
try {
203-
$"($parsed.name):(if ($parsed.value | str trim | is-empty) { '' } else { $"(char space)(char dq)($parsed.value | str trim)(char dq)" })"
204-
} catch {
205-
$"($it)"
206-
}
207-
}
208-
209-
let params = ([
210-
"show"
211-
] | append ([
212-
$pos_query
213-
(do $flagify query $query)
214-
(do $flagify id $id)
215-
(do $flagify name $name)
216-
(do $flagify moniker $moniker)
217-
(do $flagify version $version)
218-
(do $flagify source $source)
219-
#(do $flagify scope $scope)
220-
(do $flagify exact $exact)
221-
(do $flagify interactive $interactive)
222-
(do $flagify silent $silent)
223-
(do $flagify locale $locale)
224-
(do $flagify log $log)
225-
(do $flagify override $override)
226-
(do $flagify location $location)
227-
(do $flagify force $force)
228-
(do $flagify accept_package_agreements $accept_package_agreements)
229-
(do $flagify header $header)
230-
(do $flagify accept_source_agreements $accept_source_agreements)
231-
(do $flagify help $help)
232-
] | flatten) | filter { not ($in | is-empty)})
233-
234-
let output = ^winget ...$params
235-
if $raw or $help or ($output | str contains "No package selection argument was provided") {
236-
$output
237-
} else {
238-
let lines = ($output | lines)
239-
240-
if ($lines | first) =~ "Multiple packages found matching input criteria." {
241-
$"(ansi yellow)($lines | first | str trim)(ansi reset)"
242-
nu-complete winget parse table ($lines | skip 1) | select name id source
243-
} else if ($lines | first) =~ "No package found matching input criteria." {
244-
$"(ansi yellow)($lines | first | str trim)(ansi reset)"
245-
} else {
246-
let header = ($lines | first | parse -r 'Found (?P<Name>.+) \[(?P<Id>.+)\]')
247-
let manifest = ($lines | skip | each { sanitize-line } | str join (char newline) | from yaml)
248-
$header | first | merge $manifest
249-
}
250-
}
251-
}
193+
]
252194
export alias "winget view" = winget show
253195

254196
# Manage sources of packages

0 commit comments

Comments
 (0)