Script 'mail_helper' called by obssrc Hello community, here is the log from the commit of package yq for openSUSE:Factory checked in at 2023-04-15 22:33:12 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ Comparing /work/SRC/openSUSE:Factory/yq (Old) and /work/SRC/openSUSE:Factory/.yq.new.19717 (New) ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Package is "yq" Sat Apr 15 22:33:12 2023 rev:10 rq:1079557 version:4.33.3 Changes: -------- --- /work/SRC/openSUSE:Factory/yq/yq.changes 2023-03-31 21:16:10.726569401 +0200 +++ /work/SRC/openSUSE:Factory/.yq.new.19717/yq.changes 2023-04-15 22:33:13.549565180 +0200 @@ -1,0 +2,10 @@ +Fri Apr 14 17:03:43 UTC 2023 - Dirk Müller <dmuel...@suse.com> + +- update to 4.33.3: + * Fixed bug when splatting empty array #1613 + * Added scalar output for TOML (#1617) + * Fixed passing of read-only context in pipe (partial fix for + #1631) + * Bumped dependency versions + +------------------------------------------------------------------- Old: ---- yq-4.33.2.tar.gz New: ---- yq-4.33.3.tar.gz ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ Other differences: ------------------ ++++++ yq.spec ++++++ --- /var/tmp/diff_new_pack.12R7YO/_old 2023-04-15 22:33:14.065568157 +0200 +++ /var/tmp/diff_new_pack.12R7YO/_new 2023-04-15 22:33:14.069568180 +0200 @@ -20,7 +20,7 @@ %global import_path %{provider_prefix} Name: yq -Version: 4.33.2 +Version: 4.33.3 Release: 0 Summary: A portable command-line YAML processor License: MIT ++++++ vendor.tar.gz ++++++ diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/vendor/github.com/inconshreveable/mousetrap/trap_others.go new/vendor/github.com/inconshreveable/mousetrap/trap_others.go --- old/vendor/github.com/inconshreveable/mousetrap/trap_others.go 2023-03-31 09:53:37.000000000 +0200 +++ new/vendor/github.com/inconshreveable/mousetrap/trap_others.go 2023-04-14 19:03:16.000000000 +0200 @@ -1,3 +1,4 @@ +//go:build !windows // +build !windows package mousetrap diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/vendor/github.com/inconshreveable/mousetrap/trap_windows.go new/vendor/github.com/inconshreveable/mousetrap/trap_windows.go --- old/vendor/github.com/inconshreveable/mousetrap/trap_windows.go 2023-03-31 09:53:37.000000000 +0200 +++ new/vendor/github.com/inconshreveable/mousetrap/trap_windows.go 2023-04-14 19:03:16.000000000 +0200 @@ -1,81 +1,32 @@ -// +build windows -// +build !go1.4 - package mousetrap import ( - "fmt" - "os" "syscall" "unsafe" ) -const ( - // defined by the Win32 API - th32cs_snapprocess uintptr = 0x2 -) - -var ( - kernel = syscall.MustLoadDLL("kernel32.dll") - CreateToolhelp32Snapshot = kernel.MustFindProc("CreateToolhelp32Snapshot") - Process32First = kernel.MustFindProc("Process32FirstW") - Process32Next = kernel.MustFindProc("Process32NextW") -) - -// ProcessEntry32 structure defined by the Win32 API -type processEntry32 struct { - dwSize uint32 - cntUsage uint32 - th32ProcessID uint32 - th32DefaultHeapID int - th32ModuleID uint32 - cntThreads uint32 - th32ParentProcessID uint32 - pcPriClassBase int32 - dwFlags uint32 - szExeFile [syscall.MAX_PATH]uint16 -} - -func getProcessEntry(pid int) (pe *processEntry32, err error) { - snapshot, _, e1 := CreateToolhelp32Snapshot.Call(th32cs_snapprocess, uintptr(0)) - if snapshot == uintptr(syscall.InvalidHandle) { - err = fmt.Errorf("CreateToolhelp32Snapshot: %v", e1) - return +func getProcessEntry(pid int) (*syscall.ProcessEntry32, error) { + snapshot, err := syscall.CreateToolhelp32Snapshot(syscall.TH32CS_SNAPPROCESS, 0) + if err != nil { + return nil, err } - defer syscall.CloseHandle(syscall.Handle(snapshot)) - - var processEntry processEntry32 - processEntry.dwSize = uint32(unsafe.Sizeof(processEntry)) - ok, _, e1 := Process32First.Call(snapshot, uintptr(unsafe.Pointer(&processEntry))) - if ok == 0 { - err = fmt.Errorf("Process32First: %v", e1) - return + defer syscall.CloseHandle(snapshot) + var procEntry syscall.ProcessEntry32 + procEntry.Size = uint32(unsafe.Sizeof(procEntry)) + if err = syscall.Process32First(snapshot, &procEntry); err != nil { + return nil, err } - for { - if processEntry.th32ProcessID == uint32(pid) { - pe = &processEntry - return + if procEntry.ProcessID == uint32(pid) { + return &procEntry, nil } - - ok, _, e1 = Process32Next.Call(snapshot, uintptr(unsafe.Pointer(&processEntry))) - if ok == 0 { - err = fmt.Errorf("Process32Next: %v", e1) - return + err = syscall.Process32Next(snapshot, &procEntry) + if err != nil { + return nil, err } } } -func getppid() (pid int, err error) { - pe, err := getProcessEntry(os.Getpid()) - if err != nil { - return - } - - pid = int(pe.th32ParentProcessID) - return -} - // StartedByExplorer returns true if the program was invoked by the user double-clicking // on the executable from explorer.exe // @@ -83,16 +34,9 @@ // It does not guarantee that the program was run from a terminal. It only can tell you // whether it was launched from explorer.exe func StartedByExplorer() bool { - ppid, err := getppid() + pe, err := getProcessEntry(syscall.Getppid()) if err != nil { return false } - - pe, err := getProcessEntry(ppid) - if err != nil { - return false - } - - name := syscall.UTF16ToString(pe.szExeFile[:]) - return name == "explorer.exe" + return "explorer.exe" == syscall.UTF16ToString(pe.ExeFile[:]) } diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/vendor/github.com/inconshreveable/mousetrap/trap_windows_1.4.go new/vendor/github.com/inconshreveable/mousetrap/trap_windows_1.4.go --- old/vendor/github.com/inconshreveable/mousetrap/trap_windows_1.4.go 2023-03-31 09:53:37.000000000 +0200 +++ new/vendor/github.com/inconshreveable/mousetrap/trap_windows_1.4.go 1970-01-01 01:00:00.000000000 +0100 @@ -1,46 +0,0 @@ -// +build windows -// +build go1.4 - -package mousetrap - -import ( - "os" - "syscall" - "unsafe" -) - -func getProcessEntry(pid int) (*syscall.ProcessEntry32, error) { - snapshot, err := syscall.CreateToolhelp32Snapshot(syscall.TH32CS_SNAPPROCESS, 0) - if err != nil { - return nil, err - } - defer syscall.CloseHandle(snapshot) - var procEntry syscall.ProcessEntry32 - procEntry.Size = uint32(unsafe.Sizeof(procEntry)) - if err = syscall.Process32First(snapshot, &procEntry); err != nil { - return nil, err - } - for { - if procEntry.ProcessID == uint32(pid) { - return &procEntry, nil - } - err = syscall.Process32Next(snapshot, &procEntry) - if err != nil { - return nil, err - } - } -} - -// StartedByExplorer returns true if the program was invoked by the user double-clicking -// on the executable from explorer.exe -// -// It is conservative and returns false if any of the internal calls fail. -// It does not guarantee that the program was run from a terminal. It only can tell you -// whether it was launched from explorer.exe -func StartedByExplorer() bool { - pe, err := getProcessEntry(os.Getppid()) - if err != nil { - return false - } - return "explorer.exe" == syscall.UTF16ToString(pe.ExeFile[:]) -} diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/vendor/github.com/spf13/cobra/.golangci.yml new/vendor/github.com/spf13/cobra/.golangci.yml --- old/vendor/github.com/spf13/cobra/.golangci.yml 2023-03-31 09:53:37.000000000 +0200 +++ new/vendor/github.com/spf13/cobra/.golangci.yml 2023-04-14 19:03:16.000000000 +0200 @@ -1,4 +1,4 @@ -# Copyright 2013-2022 The Cobra Authors +# Copyright 2013-2023 The Cobra Authors # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/vendor/github.com/spf13/cobra/Makefile new/vendor/github.com/spf13/cobra/Makefile --- old/vendor/github.com/spf13/cobra/Makefile 2023-03-31 09:53:37.000000000 +0200 +++ new/vendor/github.com/spf13/cobra/Makefile 2023-04-14 19:03:16.000000000 +0200 @@ -5,10 +5,6 @@ $(warning "could not find golangci-lint in $(PATH), run: curl -sfL https://install.goreleaser.com/github.com/golangci/golangci-lint.sh | sh") endif -ifeq (, $(shell which richgo)) -$(warning "could not find richgo in $(PATH), run: go install github.com/kyoh86/richgo@latest") -endif - .PHONY: fmt lint test install_deps clean default: all @@ -25,6 +21,10 @@ test: install_deps $(info ******************** running tests ********************) + go test -v ./... + +richtest: install_deps + $(info ******************** running tests with kyoh86/richgo ********************) richgo test -v ./... install_deps: diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/vendor/github.com/spf13/cobra/README.md new/vendor/github.com/spf13/cobra/README.md --- old/vendor/github.com/spf13/cobra/README.md 2023-03-31 09:53:37.000000000 +0200 +++ new/vendor/github.com/spf13/cobra/README.md 2023-04-14 19:03:16.000000000 +0200 @@ -1,4 +1,4 @@ - + Cobra is a library for creating powerful modern CLI applications. @@ -6,7 +6,7 @@ [Hugo](https://gohugo.io), and [GitHub CLI](https://github.com/cli/cli) to name a few. [This list](./projects_using_cobra.md) contains a more extensive list of projects using Cobra. -[](https://github.com/spf13/cobra/actions?query=workflow%3ATest) +[](https://github.com/spf13/cobra/actions?query=workflow%3ATest) [](https://pkg.go.dev/github.com/spf13/cobra) [](https://goreportcard.com/report/github.com/spf13/cobra) [](https://gophers.slack.com/archives/CD3LP1199) diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/vendor/github.com/spf13/cobra/active_help.go new/vendor/github.com/spf13/cobra/active_help.go --- old/vendor/github.com/spf13/cobra/active_help.go 2023-03-31 09:53:37.000000000 +0200 +++ new/vendor/github.com/spf13/cobra/active_help.go 2023-04-14 19:03:16.000000000 +0200 @@ -1,4 +1,4 @@ -// Copyright 2013-2022 The Cobra Authors +// Copyright 2013-2023 The Cobra Authors // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/vendor/github.com/spf13/cobra/args.go new/vendor/github.com/spf13/cobra/args.go --- old/vendor/github.com/spf13/cobra/args.go 2023-03-31 09:53:37.000000000 +0200 +++ new/vendor/github.com/spf13/cobra/args.go 2023-04-14 19:03:16.000000000 +0200 @@ -1,4 +1,4 @@ -// Copyright 2013-2022 The Cobra Authors +// Copyright 2013-2023 The Cobra Authors // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. @@ -21,7 +21,7 @@ type PositionalArgs func(cmd *Command, args []string) error -// Legacy arg validation has the following behaviour: +// legacyArgs validation has the following behaviour: // - root commands with no subcommands can take arbitrary arguments // - root commands with subcommands will do subcommand validity checking // - subcommands will always accept arbitrary arguments diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/vendor/github.com/spf13/cobra/bash_completions.go new/vendor/github.com/spf13/cobra/bash_completions.go --- old/vendor/github.com/spf13/cobra/bash_completions.go 2023-03-31 09:53:37.000000000 +0200 +++ new/vendor/github.com/spf13/cobra/bash_completions.go 2023-04-14 19:03:16.000000000 +0200 @@ -1,4 +1,4 @@ -// Copyright 2013-2022 The Cobra Authors +// Copyright 2013-2023 The Cobra Authors // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. @@ -532,7 +532,7 @@ } } -// Setup annotations for go completions for registered flags +// prepareCustomAnnotationsForFlags setup annotations for go completions for registered flags func prepareCustomAnnotationsForFlags(cmd *Command) { flagCompletionMutex.RLock() defer flagCompletionMutex.RUnlock() diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/vendor/github.com/spf13/cobra/bash_completionsV2.go new/vendor/github.com/spf13/cobra/bash_completionsV2.go --- old/vendor/github.com/spf13/cobra/bash_completionsV2.go 2023-03-31 09:53:37.000000000 +0200 +++ new/vendor/github.com/spf13/cobra/bash_completionsV2.go 2023-04-14 19:03:16.000000000 +0200 @@ -1,4 +1,4 @@ -// Copyright 2013-2022 The Cobra Authors +// Copyright 2013-2023 The Cobra Authors // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. @@ -38,7 +38,7 @@ __%[1]s_debug() { - if [[ -n ${BASH_COMP_DEBUG_FILE:-} ]]; then + if [[ -n ${BASH_COMP_DEBUG_FILE-} ]]; then echo "$*" >> "${BASH_COMP_DEBUG_FILE}" fi } @@ -65,7 +65,7 @@ lastChar=${lastParam:$((${#lastParam}-1)):1} __%[1]s_debug "lastParam ${lastParam}, lastChar ${lastChar}" - if [ -z "${cur}" ] && [ "${lastChar}" != "=" ]; then + if [[ -z ${cur} && ${lastChar} != = ]]; then # If the last parameter is complete (there is a space following it) # We add an extra empty parameter so we can indicate this to the go method. __%[1]s_debug "Adding extra empty parameter" @@ -75,7 +75,7 @@ # When completing a flag with an = (e.g., %[1]s -n=<TAB>) # bash focuses on the part after the =, so we need to remove # the flag part from $cur - if [[ "${cur}" == -*=* ]]; then + if [[ ${cur} == -*=* ]]; then cur="${cur#*=}" fi @@ -87,7 +87,7 @@ directive=${out##*:} # Remove the directive out=${out%%:*} - if [ "${directive}" = "${out}" ]; then + if [[ ${directive} == "${out}" ]]; then # There is not directive specified directive=0 fi @@ -101,22 +101,36 @@ local shellCompDirectiveNoFileComp=%[5]d local shellCompDirectiveFilterFileExt=%[6]d local shellCompDirectiveFilterDirs=%[7]d + local shellCompDirectiveKeepOrder=%[8]d - if [ $((directive & shellCompDirectiveError)) -ne 0 ]; then + if (((directive & shellCompDirectiveError) != 0)); then # Error code. No completion. __%[1]s_debug "Received error from custom completion go code" return else - if [ $((directive & shellCompDirectiveNoSpace)) -ne 0 ]; then - if [[ $(type -t compopt) = "builtin" ]]; then + if (((directive & shellCompDirectiveNoSpace) != 0)); then + if [[ $(type -t compopt) == builtin ]]; then __%[1]s_debug "Activating no space" compopt -o nospace else __%[1]s_debug "No space directive not supported in this version of bash" fi fi - if [ $((directive & shellCompDirectiveNoFileComp)) -ne 0 ]; then - if [[ $(type -t compopt) = "builtin" ]]; then + if (((directive & shellCompDirectiveKeepOrder) != 0)); then + if [[ $(type -t compopt) == builtin ]]; then + # no sort isn't supported for bash less than < 4.4 + if [[ ${BASH_VERSINFO[0]} -lt 4 || ( ${BASH_VERSINFO[0]} -eq 4 && ${BASH_VERSINFO[1]} -lt 4 ) ]]; then + __%[1]s_debug "No sort directive not supported in this version of bash" + else + __%[1]s_debug "Activating keep order" + compopt -o nosort + fi + else + __%[1]s_debug "No sort directive not supported in this version of bash" + fi + fi + if (((directive & shellCompDirectiveNoFileComp) != 0)); then + if [[ $(type -t compopt) == builtin ]]; then __%[1]s_debug "Activating no file completion" compopt +o default else @@ -130,7 +144,7 @@ local activeHelp=() __%[1]s_extract_activeHelp - if [ $((directive & shellCompDirectiveFilterFileExt)) -ne 0 ]; then + if (((directive & shellCompDirectiveFilterFileExt) != 0)); then # File extension filtering local fullFilter filter filteringCmd @@ -143,13 +157,12 @@ filteringCmd="_filedir $fullFilter" __%[1]s_debug "File filtering command: $filteringCmd" $filteringCmd - elif [ $((directive & shellCompDirectiveFilterDirs)) -ne 0 ]; then + elif (((directive & shellCompDirectiveFilterDirs) != 0)); then # File completion for directories only - # Use printf to strip any trailing newline local subdir - subdir=$(printf "%%s" "${completions[0]}") - if [ -n "$subdir" ]; then + subdir=${completions[0]} + if [[ -n $subdir ]]; then __%[1]s_debug "Listing directories in $subdir" pushd "$subdir" >/dev/null 2>&1 && _filedir -d && popd >/dev/null 2>&1 || return else @@ -164,7 +177,7 @@ __%[1]s_handle_special_char "$cur" = # Print the activeHelp statements before we finish - if [ ${#activeHelp[*]} -ne 0 ]; then + if ((${#activeHelp[*]} != 0)); then printf "\n"; printf "%%s\n" "${activeHelp[@]}" printf "\n" @@ -184,21 +197,21 @@ # Separate activeHelp lines from real completions. # Fills the $activeHelp and $completions arrays. __%[1]s_extract_activeHelp() { - local activeHelpMarker="%[8]s" + local activeHelpMarker="%[9]s" local endIndex=${#activeHelpMarker} while IFS='' read -r comp; do - if [ "${comp:0:endIndex}" = "$activeHelpMarker" ]; then + if [[ ${comp:0:endIndex} == $activeHelpMarker ]]; then comp=${comp:endIndex} __%[1]s_debug "ActiveHelp found: $comp" - if [ -n "$comp" ]; then + if [[ -n $comp ]]; then activeHelp+=("$comp") fi else # Not an activeHelp line but a normal completion completions+=("$comp") fi - done < <(printf "%%s\n" "${out}") + done <<<"${out}" } __%[1]s_handle_completion_types() { @@ -254,7 +267,7 @@ done < <(printf "%%s\n" "${completions[@]}") # If there is a single completion left, remove the description text - if [ ${#COMPREPLY[*]} -eq 1 ]; then + if ((${#COMPREPLY[*]} == 1)); then __%[1]s_debug "COMPREPLY[0]: ${COMPREPLY[0]}" comp="${COMPREPLY[0]%%%%$tab*}" __%[1]s_debug "Removed description from single completion, which is now: ${comp}" @@ -271,8 +284,8 @@ if [[ "$comp" == *${char}* && "$COMP_WORDBREAKS" == *${char}* ]]; then local word=${comp%%"${comp##*${char}}"} local idx=${#COMPREPLY[*]} - while [[ $((--idx)) -ge 0 ]]; do - COMPREPLY[$idx]=${COMPREPLY[$idx]#"$word"} + while ((--idx >= 0)); do + COMPREPLY[idx]=${COMPREPLY[idx]#"$word"} done fi } @@ -298,7 +311,7 @@ # Make sure we can fit a description of at least 8 characters # if we are to align the descriptions. - if [[ $maxdesclength -gt 8 ]]; then + if ((maxdesclength > 8)); then # Add the proper number of spaces to align the descriptions for ((i = ${#comp} ; i < longest ; i++)); do comp+=" " @@ -310,8 +323,8 @@ # If there is enough space for any description text, # truncate the descriptions that are too long for the shell width - if [ $maxdesclength -gt 0 ]; then - if [ ${#desc} -gt $maxdesclength ]; then + if ((maxdesclength > 0)); then + if ((${#desc} > maxdesclength)); then desc=${desc:0:$(( maxdesclength - 1 ))} desc+="â¦" fi @@ -332,9 +345,9 @@ # Call _init_completion from the bash-completion package # to prepare the arguments properly if declare -F _init_completion >/dev/null 2>&1; then - _init_completion -n "=:" || return + _init_completion -n =: || return else - __%[1]s_init_completion -n "=:" || return + __%[1]s_init_completion -n =: || return fi __%[1]s_debug @@ -361,7 +374,7 @@ # ex: ts=4 sw=4 et filetype=sh `, name, compCmd, ShellCompDirectiveError, ShellCompDirectiveNoSpace, ShellCompDirectiveNoFileComp, - ShellCompDirectiveFilterFileExt, ShellCompDirectiveFilterDirs, + ShellCompDirectiveFilterFileExt, ShellCompDirectiveFilterDirs, ShellCompDirectiveKeepOrder, activeHelpMarker)) } diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/vendor/github.com/spf13/cobra/cobra.go new/vendor/github.com/spf13/cobra/cobra.go --- old/vendor/github.com/spf13/cobra/cobra.go 2023-03-31 09:53:37.000000000 +0200 +++ new/vendor/github.com/spf13/cobra/cobra.go 2023-04-14 19:03:16.000000000 +0200 @@ -1,4 +1,4 @@ -// Copyright 2013-2022 The Cobra Authors +// Copyright 2013-2023 The Cobra Authors // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. @@ -167,8 +167,8 @@ // rpad adds padding to the right of a string. func rpad(s string, padding int) string { - template := fmt.Sprintf("%%-%ds", padding) - return fmt.Sprintf(template, s) + formattedString := fmt.Sprintf("%%-%ds", padding) + return fmt.Sprintf(formattedString, s) } // tmpl executes the given template text on data, writing the result to w. diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/vendor/github.com/spf13/cobra/command.go new/vendor/github.com/spf13/cobra/command.go --- old/vendor/github.com/spf13/cobra/command.go 2023-03-31 09:53:37.000000000 +0200 +++ new/vendor/github.com/spf13/cobra/command.go 2023-04-14 19:03:16.000000000 +0200 @@ -1,4 +1,4 @@ -// Copyright 2013-2022 The Cobra Authors +// Copyright 2013-2023 The Cobra Authors // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. @@ -35,7 +35,7 @@ // FParseErrWhitelist configures Flag parse errors to be ignored type FParseErrWhitelist flag.ParseErrorsWhitelist -// Structure to manage groups for commands +// Group Structure to manage groups for commands type Group struct { ID string Title string @@ -47,7 +47,7 @@ // definition to ensure usability. type Command struct { // Use is the one-line usage message. - // Recommended syntax is as follow: + // Recommended syntax is as follows: // [ ] identifies an optional argument. Arguments that are not enclosed in brackets are required. // ... indicates that you can specify multiple values for the previous argument. // | indicates mutually exclusive information. You can use the argument to the left of the separator or the @@ -321,7 +321,7 @@ c.helpCommand = cmd } -// SetHelpCommandGroup sets the group id of the help command. +// SetHelpCommandGroupID sets the group id of the help command. func (c *Command) SetHelpCommandGroupID(groupID string) { if c.helpCommand != nil { c.helpCommand.GroupID = groupID @@ -330,7 +330,7 @@ c.helpCommandGroupID = groupID } -// SetCompletionCommandGroup sets the group id of the completion command. +// SetCompletionCommandGroupID sets the group id of the completion command. func (c *Command) SetCompletionCommandGroupID(groupID string) { // completionCommandGroupID is used if no completion command is defined by the user c.Root().completionCommandGroupID = groupID @@ -655,20 +655,44 @@ // argsMinusFirstX removes only the first x from args. Otherwise, commands that look like // openshift admin policy add-role-to-user admin my-user, lose the admin argument (arg[4]). -func argsMinusFirstX(args []string, x string) []string { - for i, y := range args { - if x == y { - ret := []string{} - ret = append(ret, args[:i]...) - ret = append(ret, args[i+1:]...) - return ret +// Special care needs to be taken not to remove a flag value. +func (c *Command) argsMinusFirstX(args []string, x string) []string { + if len(args) == 0 { + return args + } + c.mergePersistentFlags() + flags := c.Flags() + +Loop: + for pos := 0; pos < len(args); pos++ { + s := args[pos] + switch { + case s == "--": + // -- means we have reached the end of the parseable args. Break out of the loop now. + break Loop + case strings.HasPrefix(s, "--") && !strings.Contains(s, "=") && !hasNoOptDefVal(s[2:], flags): + fallthrough + case strings.HasPrefix(s, "-") && !strings.Contains(s, "=") && len(s) == 2 && !shortHasNoOptDefVal(s[1:], flags): + // This is a flag without a default value, and an equal sign is not used. Increment pos in order to skip + // over the next arg, because that is the value of this flag. + pos++ + continue + case !strings.HasPrefix(s, "-"): + // This is not a flag or a flag value. Check to see if it matches what we're looking for, and if so, + // return the args, excluding the one at this position. + if s == x { + ret := []string{} + ret = append(ret, args[:pos]...) + ret = append(ret, args[pos+1:]...) + return ret + } } } return args } func isFlagArg(arg string) bool { - return ((len(arg) >= 3 && arg[1] == '-') || + return ((len(arg) >= 3 && arg[0:2] == "--") || (len(arg) >= 2 && arg[0] == '-' && arg[1] != '-')) } @@ -686,7 +710,7 @@ cmd := c.findNext(nextSubCmd) if cmd != nil { - return innerfind(cmd, argsMinusFirstX(innerArgs, nextSubCmd)) + return innerfind(cmd, c.argsMinusFirstX(innerArgs, nextSubCmd)) } return c, innerArgs } @@ -1272,7 +1296,7 @@ return true } -// ContainGroups return if groupID exists in the list of command groups. +// ContainsGroup return if groupID exists in the list of command groups. func (c *Command) ContainsGroup(groupID string) bool { for _, x := range c.commandgroups { if x.ID == groupID { diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/vendor/github.com/spf13/cobra/command_notwin.go new/vendor/github.com/spf13/cobra/command_notwin.go --- old/vendor/github.com/spf13/cobra/command_notwin.go 2023-03-31 09:53:37.000000000 +0200 +++ new/vendor/github.com/spf13/cobra/command_notwin.go 2023-04-14 19:03:16.000000000 +0200 @@ -1,4 +1,4 @@ -// Copyright 2013-2022 The Cobra Authors +// Copyright 2013-2023 The Cobra Authors // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/vendor/github.com/spf13/cobra/command_win.go new/vendor/github.com/spf13/cobra/command_win.go --- old/vendor/github.com/spf13/cobra/command_win.go 2023-03-31 09:53:37.000000000 +0200 +++ new/vendor/github.com/spf13/cobra/command_win.go 2023-04-14 19:03:16.000000000 +0200 @@ -1,4 +1,4 @@ -// Copyright 2013-2022 The Cobra Authors +// Copyright 2013-2023 The Cobra Authors // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/vendor/github.com/spf13/cobra/completions.go new/vendor/github.com/spf13/cobra/completions.go --- old/vendor/github.com/spf13/cobra/completions.go 2023-03-31 09:53:37.000000000 +0200 +++ new/vendor/github.com/spf13/cobra/completions.go 2023-04-14 19:03:16.000000000 +0200 @@ -1,4 +1,4 @@ -// Copyright 2013-2022 The Cobra Authors +// Copyright 2013-2023 The Cobra Authors // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. @@ -77,6 +77,10 @@ // obtain the same behavior but only for flags. ShellCompDirectiveFilterDirs + // ShellCompDirectiveKeepOrder indicates that the shell should preserve the order + // in which the completions are provided + ShellCompDirectiveKeepOrder + // =========================================================================== // All directives using iota should be above this one. @@ -159,6 +163,9 @@ if d&ShellCompDirectiveFilterDirs != 0 { directives = append(directives, "ShellCompDirectiveFilterDirs") } + if d&ShellCompDirectiveKeepOrder != 0 { + directives = append(directives, "ShellCompDirectiveKeepOrder") + } if len(directives) == 0 { directives = append(directives, "ShellCompDirectiveDefault") } @@ -169,7 +176,7 @@ return strings.Join(directives, ", ") } -// Adds a special hidden command that can be used to request custom completions. +// initCompleteCmd adds a special hidden command that can be used to request custom completions. func (c *Command) initCompleteCmd(args []string) { completeCmd := &Command{ Use: fmt.Sprintf("%s [command-line]", ShellCompRequestCmd), @@ -727,7 +734,7 @@ To load completions in your current shell session: - source <(%[1]s completion zsh); compdef _%[1]s %[1]s + source <(%[1]s completion zsh) To load completions for every new session, execute once: diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/vendor/github.com/spf13/cobra/fish_completions.go new/vendor/github.com/spf13/cobra/fish_completions.go --- old/vendor/github.com/spf13/cobra/fish_completions.go 2023-03-31 09:53:37.000000000 +0200 +++ new/vendor/github.com/spf13/cobra/fish_completions.go 2023-04-14 19:03:16.000000000 +0200 @@ -1,4 +1,4 @@ -// Copyright 2013-2022 The Cobra Authors +// Copyright 2013-2023 The Cobra Authors // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. @@ -53,7 +53,7 @@ __%[1]s_debug "last arg: $lastArg" # Disable ActiveHelp which is not supported for fish shell - set -l requestComp "%[9]s=0 $args[1] %[3]s $args[2..-1] $lastArg" + set -l requestComp "%[10]s=0 $args[1] %[3]s $args[2..-1] $lastArg" __%[1]s_debug "Calling $requestComp" set -l results (eval $requestComp 2> /dev/null) @@ -89,6 +89,60 @@ printf "%%s\n" "$directiveLine" end +# this function limits calls to __%[1]s_perform_completion, by caching the result behind $__%[1]s_perform_completion_once_result +function __%[1]s_perform_completion_once + __%[1]s_debug "Starting __%[1]s_perform_completion_once" + + if test -n "$__%[1]s_perform_completion_once_result" + __%[1]s_debug "Seems like a valid result already exists, skipping __%[1]s_perform_completion" + return 0 + end + + set --global __%[1]s_perform_completion_once_result (__%[1]s_perform_completion) + if test -z "$__%[1]s_perform_completion_once_result" + __%[1]s_debug "No completions, probably due to a failure" + return 1 + end + + __%[1]s_debug "Performed completions and set __%[1]s_perform_completion_once_result" + return 0 +end + +# this function is used to clear the $__%[1]s_perform_completion_once_result variable after completions are run +function __%[1]s_clear_perform_completion_once_result + __%[1]s_debug "" + __%[1]s_debug "========= clearing previously set __%[1]s_perform_completion_once_result variable ==========" + set --erase __%[1]s_perform_completion_once_result + __%[1]s_debug "Succesfully erased the variable __%[1]s_perform_completion_once_result" +end + +function __%[1]s_requires_order_preservation + __%[1]s_debug "" + __%[1]s_debug "========= checking if order preservation is required ==========" + + __%[1]s_perform_completion_once + if test -z "$__%[1]s_perform_completion_once_result" + __%[1]s_debug "Error determining if order preservation is required" + return 1 + end + + set -l directive (string sub --start 2 $__%[1]s_perform_completion_once_result[-1]) + __%[1]s_debug "Directive is: $directive" + + set -l shellCompDirectiveKeepOrder %[9]d + set -l keeporder (math (math --scale 0 $directive / $shellCompDirectiveKeepOrder) %% 2) + __%[1]s_debug "Keeporder is: $keeporder" + + if test $keeporder -ne 0 + __%[1]s_debug "This does require order preservation" + return 0 + end + + __%[1]s_debug "This doesn't require order preservation" + return 1 +end + + # This function does two things: # - Obtain the completions and store them in the global __%[1]s_comp_results # - Return false if file completion should be performed @@ -99,17 +153,17 @@ # Start fresh set --erase __%[1]s_comp_results - set -l results (__%[1]s_perform_completion) - __%[1]s_debug "Completion results: $results" + __%[1]s_perform_completion_once + __%[1]s_debug "Completion results: $__%[1]s_perform_completion_once_result" - if test -z "$results" + if test -z "$__%[1]s_perform_completion_once_result" __%[1]s_debug "No completion, probably due to a failure" # Might as well do file completion, in case it helps return 1 end - set -l directive (string sub --start 2 $results[-1]) - set --global __%[1]s_comp_results $results[1..-2] + set -l directive (string sub --start 2 $__%[1]s_perform_completion_once_result[-1]) + set --global __%[1]s_comp_results $__%[1]s_perform_completion_once_result[1..-2] __%[1]s_debug "Completions are: $__%[1]s_comp_results" __%[1]s_debug "Directive is: $directive" @@ -205,13 +259,17 @@ # Remove any pre-existing completions for the program since we will be handling all of them. complete -c %[2]s -e +# this will get called after the two calls below and clear the $__%[1]s_perform_completion_once_result global +complete -c %[2]s -n '__%[1]s_clear_perform_completion_once_result' # The call to __%[1]s_prepare_completions will setup __%[1]s_comp_results # which provides the program's completion choices. -complete -c %[2]s -n '__%[1]s_prepare_completions' -f -a '$__%[1]s_comp_results' - +# If this doesn't require order preservation, we don't use the -k flag +complete -c %[2]s -n 'not __%[1]s_requires_order_preservation && __%[1]s_prepare_completions' -f -a '$__%[1]s_comp_results' +# otherwise we use the -k flag +complete -k -c %[2]s -n '__%[1]s_requires_order_preservation && __%[1]s_prepare_completions' -f -a '$__%[1]s_comp_results' `, nameForVar, name, compCmd, ShellCompDirectiveError, ShellCompDirectiveNoSpace, ShellCompDirectiveNoFileComp, - ShellCompDirectiveFilterFileExt, ShellCompDirectiveFilterDirs, activeHelpEnvVar(name))) + ShellCompDirectiveFilterFileExt, ShellCompDirectiveFilterDirs, ShellCompDirectiveKeepOrder, activeHelpEnvVar(name))) } // GenFishCompletion generates fish completion file and writes to the passed writer. diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/vendor/github.com/spf13/cobra/flag_groups.go new/vendor/github.com/spf13/cobra/flag_groups.go --- old/vendor/github.com/spf13/cobra/flag_groups.go 2023-03-31 09:53:37.000000000 +0200 +++ new/vendor/github.com/spf13/cobra/flag_groups.go 2023-04-14 19:03:16.000000000 +0200 @@ -1,4 +1,4 @@ -// Copyright 2013-2022 The Cobra Authors +// Copyright 2013-2023 The Cobra Authors // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/vendor/github.com/spf13/cobra/powershell_completions.go new/vendor/github.com/spf13/cobra/powershell_completions.go --- old/vendor/github.com/spf13/cobra/powershell_completions.go 2023-03-31 09:53:37.000000000 +0200 +++ new/vendor/github.com/spf13/cobra/powershell_completions.go 2023-04-14 19:03:16.000000000 +0200 @@ -1,4 +1,4 @@ -// Copyright 2013-2022 The Cobra Authors +// Copyright 2013-2023 The Cobra Authors // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. @@ -77,6 +77,7 @@ $ShellCompDirectiveNoFileComp=%[6]d $ShellCompDirectiveFilterFileExt=%[7]d $ShellCompDirectiveFilterDirs=%[8]d + $ShellCompDirectiveKeepOrder=%[9]d # Prepare the command to request completions for the program. # Split the command at the first space to separate the program and arguments. @@ -106,13 +107,22 @@ # If the last parameter is complete (there is a space following it) # We add an extra empty parameter so we can indicate this to the go method. __%[1]s_debug "Adding extra empty parameter" -`+" # We need to use `\"`\" to pass an empty argument a \"\" or '' does not work!!!"+` -`+" $RequestComp=\"$RequestComp\" + ' `\"`\"'"+` + # PowerShell 7.2+ changed the way how the arguments are passed to executables, + # so for pre-7.2 or when Legacy argument passing is enabled we need to use +`+" # `\"`\" to pass an empty argument, a \"\" or '' does not work!!!"+` + if ($PSVersionTable.PsVersion -lt [version]'7.2.0' -or + ($PSVersionTable.PsVersion -lt [version]'7.3.0' -and -not [ExperimentalFeature]::IsEnabled("PSNativeCommandArgumentPassing")) -or + (($PSVersionTable.PsVersion -ge [version]'7.3.0' -or [ExperimentalFeature]::IsEnabled("PSNativeCommandArgumentPassing")) -and + $PSNativeCommandArgumentPassing -eq 'Legacy')) { +`+" $RequestComp=\"$RequestComp\" + ' `\"`\"'"+` + } else { + $RequestComp="$RequestComp" + ' ""' + } } __%[1]s_debug "Calling $RequestComp" # First disable ActiveHelp which is not supported for Powershell - $env:%[9]s=0 + $env:%[10]s=0 #call the command store the output in $out and redirect stderr and stdout to null # $Out is an array contains each line per element @@ -137,7 +147,7 @@ } $Longest = 0 - $Values = $Out | ForEach-Object { + [Array]$Values = $Out | ForEach-Object { #Split the output in name and description `+" $Name, $Description = $_.Split(\"`t\",2)"+` __%[1]s_debug "Name: $Name Description: $Description" @@ -182,6 +192,11 @@ } } + # we sort the values in ascending order by name if keep order isn't passed + if (($Directive -band $ShellCompDirectiveKeepOrder) -eq 0 ) { + $Values = $Values | Sort-Object -Property Name + } + if (($Directive -band $ShellCompDirectiveNoFileComp) -ne 0 ) { __%[1]s_debug "ShellCompDirectiveNoFileComp is called" @@ -267,7 +282,7 @@ Register-ArgumentCompleter -CommandName '%[1]s' -ScriptBlock $__%[2]sCompleterBlock `, name, nameForVar, compCmd, ShellCompDirectiveError, ShellCompDirectiveNoSpace, ShellCompDirectiveNoFileComp, - ShellCompDirectiveFilterFileExt, ShellCompDirectiveFilterDirs, activeHelpEnvVar(name))) + ShellCompDirectiveFilterFileExt, ShellCompDirectiveFilterDirs, ShellCompDirectiveKeepOrder, activeHelpEnvVar(name))) } func (c *Command) genPowerShellCompletion(w io.Writer, includeDesc bool) error { diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/vendor/github.com/spf13/cobra/projects_using_cobra.md new/vendor/github.com/spf13/cobra/projects_using_cobra.md --- old/vendor/github.com/spf13/cobra/projects_using_cobra.md 2023-03-31 09:53:37.000000000 +0200 +++ new/vendor/github.com/spf13/cobra/projects_using_cobra.md 2023-04-14 19:03:16.000000000 +0200 @@ -1,11 +1,13 @@ ## Projects using Cobra - [Allero](https://github.com/allero-io/allero) +- [Arewefastyet](https://benchmark.vitess.io) - [Arduino CLI](https://github.com/arduino/arduino-cli) - [Bleve](https://blevesearch.com/) - [Cilium](https://cilium.io/) - [CloudQuery](https://github.com/cloudquery/cloudquery) - [CockroachDB](https://www.cockroachlabs.com/) +- [Constellation](https://github.com/edgelesssys/constellation) - [Cosmos SDK](https://github.com/cosmos/cosmos-sdk) - [Datree](https://github.com/datreeio/datree) - [Delve](https://github.com/derekparker/delve) @@ -25,7 +27,7 @@ - [Istio](https://istio.io) - [Kool](https://github.com/kool-dev/kool) - [Kubernetes](https://kubernetes.io/) -- [Kubescape](https://github.com/armosec/kubescape) +- [Kubescape](https://github.com/kubescape/kubescape) - [KubeVirt](https://github.com/kubevirt/kubevirt) - [Linkerd](https://linkerd.io/) - [Mattermost-server](https://github.com/mattermost/mattermost-server) @@ -51,10 +53,12 @@ - [Random](https://github.com/erdaltsksn/random) - [Rclone](https://rclone.org/) - [Scaleway CLI](https://github.com/scaleway/scaleway-cli) +- [Sia](https://github.com/SiaFoundation/siad) - [Skaffold](https://skaffold.dev/) - [Tendermint](https://github.com/tendermint/tendermint) - [Twitch CLI](https://github.com/twitchdev/twitch-cli) - [UpCloud CLI (`upctl`)](https://github.com/UpCloudLtd/upcloud-cli) +- [Vitess](https://vitess.io) - VMware's [Tanzu Community Edition](https://github.com/vmware-tanzu/community-edition) & [Tanzu Framework](https://github.com/vmware-tanzu/tanzu-framework) - [Werf](https://werf.io/) - [ZITADEL](https://github.com/zitadel/zitadel) diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/vendor/github.com/spf13/cobra/shell_completions.go new/vendor/github.com/spf13/cobra/shell_completions.go --- old/vendor/github.com/spf13/cobra/shell_completions.go 2023-03-31 09:53:37.000000000 +0200 +++ new/vendor/github.com/spf13/cobra/shell_completions.go 2023-04-14 19:03:16.000000000 +0200 @@ -1,4 +1,4 @@ -// Copyright 2013-2022 The Cobra Authors +// Copyright 2013-2023 The Cobra Authors // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/vendor/github.com/spf13/cobra/shell_completions.md new/vendor/github.com/spf13/cobra/shell_completions.md --- old/vendor/github.com/spf13/cobra/shell_completions.md 2023-03-31 09:53:37.000000000 +0200 +++ new/vendor/github.com/spf13/cobra/shell_completions.md 2023-04-14 19:03:16.000000000 +0200 @@ -71,7 +71,7 @@ `,cmd.Root().Name()), DisableFlagsInUseLine: true, ValidArgs: []string{"bash", "zsh", "fish", "powershell"}, - Args: cobra.ExactValidArgs(1), + Args: cobra.MatchAll(cobra.ExactArgs(1), cobra.OnlyValidArgs), Run: func(cmd *cobra.Command, args []string) { switch args[0] { case "bash": @@ -162,16 +162,7 @@ } ``` -The aliases are not shown to the user on tab completion, but they are accepted as valid nouns by -the completion algorithm if entered manually, e.g. in: - -```bash -$ kubectl get rc [tab][tab] -backend frontend database -``` - -Note that without declaring `rc` as an alias, the completion algorithm would not know to show the list of -replication controllers following `rc`. +The aliases are shown to the user on tab completion only if no completions were found within sub-commands or `ValidArgs`. ### Dynamic completion of nouns @@ -237,6 +228,10 @@ // return []string{"themes"}, ShellCompDirectiveFilterDirs // ShellCompDirectiveFilterDirs + +// ShellCompDirectiveKeepOrder indicates that the shell should preserve the order +// in which the completions are provided +ShellCompDirectiveKeepOrder ``` ***Note***: When using the `ValidArgsFunction`, Cobra will call your registered function after having parsed all flags and arguments provided in the command-line. You therefore don't need to do this parsing yourself. For example, when a user calls `helm status --namespace my-rook-ns [tab][tab]`, Cobra will call your registered `ValidArgsFunction` after having parsed the `--namespace` flag, as it would have done when calling the `RunE` function. @@ -385,6 +380,19 @@ ```go ValidArgs: []string{"bash\tCompletions for bash", "zsh\tCompletions for zsh"} ``` + +If you don't want to show descriptions in the completions, you can add `--no-descriptions` to the default `completion` command to disable them, like: + +```bash +$ source <(helm completion bash) +$ helm completion [tab][tab] +bash (generate autocompletion script for bash) powershell (generate autocompletion script for powershell) +fish (generate autocompletion script for fish) zsh (generate autocompletion script for zsh) + +$ source <(helm completion bash --no-descriptions) +$ helm completion [tab][tab] +bash fish powershell zsh +``` ## Bash completions ### Dependencies diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/vendor/github.com/spf13/cobra/user_guide.md new/vendor/github.com/spf13/cobra/user_guide.md --- old/vendor/github.com/spf13/cobra/user_guide.md 2023-03-31 09:53:37.000000000 +0200 +++ new/vendor/github.com/spf13/cobra/user_guide.md 2023-04-14 19:03:16.000000000 +0200 @@ -188,6 +188,37 @@ } ``` +### Organizing subcommands + +A command may have subcommands which in turn may have other subcommands. This is achieved by using +`AddCommand`. In some cases, especially in larger applications, each subcommand may be defined in +its own go package. + +The suggested approach is for the parent command to use `AddCommand` to add its most immediate +subcommands. For example, consider the following directory structure: + +```text +âââ cmd +â  âââ root.go +â  âââ sub1 +â  âââ sub1.go +â  âââ sub2 +â  âââ leafA.go +â  âââ leafB.go +â  âââ sub2.go +âââ main.go +``` + +In this case: + +* The `init` function of `root.go` adds the command defined in `sub1.go` to the root command. +* The `init` function of `sub1.go` adds the command defined in `sub2.go` to the sub1 command. +* The `init` function of `sub2.go` adds the commands defined in `leafA.go` and `leafB.go` to the + sub2 command. + +This approach ensures the subcommands are always included at compile time while avoiding cyclic +references. + ### Returning and handling errors If you wish to return an error to the caller of a command, `RunE` can be used. @@ -313,8 +344,8 @@ You can also prevent different flags from being provided together if they represent mutually exclusive options such as specifying an output format as either `--json` or `--yaml` but never both: ```go -rootCmd.Flags().BoolVar(&u, "json", false, "Output in JSON") -rootCmd.Flags().BoolVar(&pw, "yaml", false, "Output in YAML") +rootCmd.Flags().BoolVar(&ofJson, "json", false, "Output in JSON") +rootCmd.Flags().BoolVar(&ofYaml, "yaml", false, "Output in YAML") rootCmd.MarkFlagsMutuallyExclusive("json", "yaml") ``` @@ -349,7 +380,7 @@ ```go var cmd = &cobra.Command{ Short: "hello", - Args: MatchAll(ExactArgs(2), OnlyValidArgs), + Args: cobra.MatchAll(cobra.ExactArgs(2), cobra.OnlyValidArgs), Run: func(cmd *cobra.Command, args []string) { fmt.Println("Hello, World!") }, diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/vendor/github.com/spf13/cobra/zsh_completions.go new/vendor/github.com/spf13/cobra/zsh_completions.go --- old/vendor/github.com/spf13/cobra/zsh_completions.go 2023-03-31 09:53:37.000000000 +0200 +++ new/vendor/github.com/spf13/cobra/zsh_completions.go 2023-04-14 19:03:16.000000000 +0200 @@ -1,4 +1,4 @@ -// Copyright 2013-2022 The Cobra Authors +// Copyright 2013-2023 The Cobra Authors // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. @@ -90,6 +90,7 @@ compCmd = ShellCompNoDescRequestCmd } WriteStringAndCheck(buf, fmt.Sprintf(`#compdef %[1]s +compdef _%[1]s %[1]s # zsh completion for %-36[1]s -*- shell-script -*- @@ -108,8 +109,9 @@ local shellCompDirectiveNoFileComp=%[5]d local shellCompDirectiveFilterFileExt=%[6]d local shellCompDirectiveFilterDirs=%[7]d + local shellCompDirectiveKeepOrder=%[8]d - local lastParam lastChar flagPrefix requestComp out directive comp lastComp noSpace + local lastParam lastChar flagPrefix requestComp out directive comp lastComp noSpace keepOrder local -a completions __%[1]s_debug "\n========= starting completion logic ==========" @@ -177,7 +179,7 @@ return fi - local activeHelpMarker="%[8]s" + local activeHelpMarker="%[9]s" local endIndex=${#activeHelpMarker} local startIndex=$((${#activeHelpMarker}+1)) local hasActiveHelp=0 @@ -227,6 +229,11 @@ noSpace="-S ''" fi + if [ $((directive & shellCompDirectiveKeepOrder)) -ne 0 ]; then + __%[1]s_debug "Activating keep order." + keepOrder="-V" + fi + if [ $((directive & shellCompDirectiveFilterFileExt)) -ne 0 ]; then # File extension filtering local filteringCmd @@ -262,7 +269,7 @@ return $result else __%[1]s_debug "Calling _describe" - if eval _describe "completions" completions $flagPrefix $noSpace; then + if eval _describe $keepOrder "completions" completions $flagPrefix $noSpace; then __%[1]s_debug "_describe found some completions" # Return the success of having called _describe @@ -296,6 +303,6 @@ fi `, name, compCmd, ShellCompDirectiveError, ShellCompDirectiveNoSpace, ShellCompDirectiveNoFileComp, - ShellCompDirectiveFilterFileExt, ShellCompDirectiveFilterDirs, + ShellCompDirectiveFilterFileExt, ShellCompDirectiveFilterDirs, ShellCompDirectiveKeepOrder, activeHelpMarker)) } diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/vendor/modules.txt new/vendor/modules.txt --- old/vendor/modules.txt 2023-03-31 09:53:38.000000000 +0200 +++ new/vendor/modules.txt 2023-04-14 19:03:16.000000000 +0200 @@ -27,14 +27,14 @@ github.com/goccy/go-json/internal/encoder/vm_indent github.com/goccy/go-json/internal/errors github.com/goccy/go-json/internal/runtime -# github.com/goccy/go-yaml v1.10.1 +# github.com/goccy/go-yaml v1.11.0 ## explicit; go 1.18 github.com/goccy/go-yaml/ast github.com/goccy/go-yaml/lexer github.com/goccy/go-yaml/printer github.com/goccy/go-yaml/scanner github.com/goccy/go-yaml/token -# github.com/inconshreveable/mousetrap v1.0.1 +# github.com/inconshreveable/mousetrap v1.1.0 ## explicit; go 1.18 github.com/inconshreveable/mousetrap # github.com/jinzhu/copier v0.3.5 @@ -62,7 +62,7 @@ github.com/pkg/diff/intern github.com/pkg/diff/myers github.com/pkg/diff/write -# github.com/spf13/cobra v1.6.1 +# github.com/spf13/cobra v1.7.0 ## explicit; go 1.15 github.com/spf13/cobra # github.com/spf13/pflag v1.0.5 ++++++ yq-4.33.2.tar.gz -> yq-4.33.3.tar.gz ++++++ diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/yq-4.33.2/Dockerfile new/yq-4.33.3/Dockerfile --- old/yq-4.33.2/Dockerfile 2023-03-31 01:21:59.000000000 +0200 +++ new/yq-4.33.3/Dockerfile 2023-04-11 04:06:26.000000000 +0200 @@ -1,4 +1,4 @@ -FROM golang:1.20.2 as builder +FROM golang:1.20.3 as builder WORKDIR /go/src/mikefarah/yq diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/yq-4.33.2/Dockerfile.dev new/yq-4.33.3/Dockerfile.dev --- old/yq-4.33.2/Dockerfile.dev 2023-03-31 01:21:59.000000000 +0200 +++ new/yq-4.33.3/Dockerfile.dev 2023-04-11 04:06:26.000000000 +0200 @@ -1,4 +1,4 @@ -FROM golang:1.20.2 +FROM golang:1.20.3 COPY scripts/devtools.sh /opt/devtools.sh diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/yq-4.33.2/README.md new/yq-4.33.3/README.md --- old/yq-4.33.2/README.md 2023-03-31 01:21:59.000000000 +0200 +++ new/yq-4.33.3/README.md 2023-04-11 04:06:26.000000000 +0200 @@ -47,7 +47,7 @@ Convert JSON to YAML ```bash -yq -P sample.json +yq -Poy sample.json ``` See the [documentation](https://mikefarah.gitbook.io/yq/) for more examples. diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/yq-4.33.2/cmd/utils.go new/yq-4.33.3/cmd/utils.go --- old/yq-4.33.2/cmd/utils.go 2023-03-31 01:21:59.000000000 +0200 +++ new/yq-4.33.3/cmd/utils.go 2023-04-11 04:06:26.000000000 +0200 @@ -75,9 +75,6 @@ } } else if isAutomaticOutputFormat() { // automatic input worked, we can do it for output too unless specified - if inputFormat == "toml" { - return "", nil, fmt.Errorf("toml is not yet supported as an output format. Please specify another output format using the [--output-format/-o] flag") - } if inputFormat == "json" { yqlib.GetLogger().Warning("JSON file output is now JSON by default (instead of yaml). Use '-oy' or '--output-format=yaml' for yaml output") } @@ -196,6 +193,8 @@ return yqlib.NewYamlEncoder(indent, colorsEnabled, yqlib.ConfiguredYamlPreferences), nil case yqlib.XMLOutputFormat: return yqlib.NewXMLEncoder(indent, yqlib.ConfiguredXMLPreferences), nil + case yqlib.TomlOutputFormat: + return yqlib.NewTomlEncoder(), nil } return nil, fmt.Errorf("invalid encoder: %v", format) } diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/yq-4.33.2/cmd/version.go new/yq-4.33.3/cmd/version.go --- old/yq-4.33.2/cmd/version.go 2023-03-31 01:21:59.000000000 +0200 +++ new/yq-4.33.3/cmd/version.go 2023-04-11 04:06:26.000000000 +0200 @@ -11,7 +11,7 @@ GitDescribe string // Version is main version number that is being run at the moment. - Version = "v4.33.2" + Version = "v4.33.3" // VersionPrerelease is a pre-release marker for the version. If this is "" (empty string) // then it means that it is a final release. Otherwise, this is a pre-release diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/yq-4.33.2/go.mod new/yq-4.33.3/go.mod --- old/yq-4.33.2/go.mod 2023-03-31 01:21:59.000000000 +0200 +++ new/yq-4.33.3/go.mod 2023-04-11 04:06:26.000000000 +0200 @@ -8,12 +8,12 @@ github.com/elliotchance/orderedmap v1.5.0 github.com/fatih/color v1.15.0 github.com/goccy/go-json v0.10.2 - github.com/goccy/go-yaml v1.10.1 + github.com/goccy/go-yaml v1.11.0 github.com/jinzhu/copier v0.3.5 github.com/magiconair/properties v1.8.7 github.com/pelletier/go-toml/v2 v2.0.7 github.com/pkg/diff v0.0.0-20210226163009-20ebb0f2a09e - github.com/spf13/cobra v1.6.1 + github.com/spf13/cobra v1.7.0 github.com/spf13/pflag v1.0.5 golang.org/x/net v0.8.0 gopkg.in/op/go-logging.v1 v1.0.0-20160211212156-b2cb9fa56473 @@ -21,7 +21,7 @@ ) require ( - github.com/inconshreveable/mousetrap v1.0.1 // indirect + github.com/inconshreveable/mousetrap v1.1.0 // indirect github.com/mattn/go-colorable v0.1.13 // indirect github.com/mattn/go-isatty v0.0.17 // indirect golang.org/x/sys v0.6.0 // indirect diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/yq-4.33.2/go.sum new/yq-4.33.3/go.sum --- old/yq-4.33.2/go.sum 2023-03-31 01:21:59.000000000 +0200 +++ new/yq-4.33.3/go.sum 2023-04-11 04:06:26.000000000 +0200 @@ -17,11 +17,11 @@ github.com/fatih/color v1.15.0/go.mod h1:0h5ZqXfHYED7Bhv2ZJamyIOUej9KtShiJESRwBDUSsw= github.com/goccy/go-json v0.10.2 h1:CrxCmQqYDkv1z7lO7Wbh2HN93uovUHgrECaO5ZrCXAU= github.com/goccy/go-json v0.10.2/go.mod h1:6MelG93GURQebXPDq3khkgXZkazVtN9CRI+MGFi0w8I= -github.com/goccy/go-yaml v1.10.1 h1:neijiyxgQOmEyVw8ZsDxcCzkU3NJ5NS+q7xmnOcd8UQ= -github.com/goccy/go-yaml v1.10.1/go.mod h1:H+mJrWtjPTJAHvRbV09MCK9xYwODM+wRTVFFTWckfng= +github.com/goccy/go-yaml v1.11.0 h1:n7Z+zx8S9f9KgzG6KtQKf+kwqXZlLNR2F6018Dgau54= +github.com/goccy/go-yaml v1.11.0/go.mod h1:H+mJrWtjPTJAHvRbV09MCK9xYwODM+wRTVFFTWckfng= github.com/hexops/gotextdiff v1.0.3 h1:gitA9+qJrrTCsiCl7+kh75nPqQt1cx4ZkudSTLoUqJM= -github.com/inconshreveable/mousetrap v1.0.1 h1:U3uMjPSQEBMNp1lFxmllqCPM6P5u/Xq7Pgzkat/bFNc= -github.com/inconshreveable/mousetrap v1.0.1/go.mod h1:vpF70FUmC8bwa3OWnCshd2FqLfsEA9PFc4w1p2J65bw= +github.com/inconshreveable/mousetrap v1.1.0 h1:wN+x4NVGpMsO7ErUn/mUI3vEoE6Jt13X2s0bqwp9tc8= +github.com/inconshreveable/mousetrap v1.1.0/go.mod h1:vpF70FUmC8bwa3OWnCshd2FqLfsEA9PFc4w1p2J65bw= github.com/jinzhu/copier v0.3.5 h1:GlvfUwHk62RokgqVNvYsku0TATCF7bAHVwEXoBh3iJg= github.com/jinzhu/copier v0.3.5/go.mod h1:DfbEm0FYsaqBcKcFuvmOZb218JkPGtvSHsKg8S8hyyg= github.com/magiconair/properties v1.8.7 h1:IeQXZAiQcpL9mgcAe1Nu6cX9LLw6ExEHKjN0VQdvPDY= @@ -38,8 +38,8 @@ github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= github.com/russross/blackfriday/v2 v2.1.0/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM= -github.com/spf13/cobra v1.6.1 h1:o94oiPyS4KD1mPy2fmcYYHHfCxLqYjJOhGsCHFZtEzA= -github.com/spf13/cobra v1.6.1/go.mod h1:IOw/AERYS7UzyrGinqmz6HLUo219MORXGxhbaJUqzrY= +github.com/spf13/cobra v1.7.0 h1:hyqWnYt1ZQShIddO5kBpj3vu05/++x6tJ6dg8EC572I= +github.com/spf13/cobra v1.7.0/go.mod h1:uLxZILRyS/50WlhOIKD7W6V5bgeIt+4sICxh6uRMrb0= github.com/spf13/pflag v1.0.5 h1:iy+VFUOCP1a+8yFto/drg2CJ5u0yRoB7fZw3DKv/JXA= github.com/spf13/pflag v1.0.5/go.mod h1:McXfInJRrz4CZXVZOBLb0bTZqETkiAhM9Iw0y3An2Bg= github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/yq-4.33.2/pkg/yqlib/doc/usage/toml.md new/yq-4.33.3/pkg/yqlib/doc/usage/toml.md --- old/yq-4.33.2/pkg/yqlib/doc/usage/toml.md 2023-03-31 01:21:59.000000000 +0200 +++ new/yq-4.33.3/pkg/yqlib/doc/usage/toml.md 2023-04-11 04:06:26.000000000 +0200 @@ -38,6 +38,22 @@ address: 12 cat st ``` +## Encode: Scalar +Given a sample.toml file of: +```toml +person.name = "hello" +person.address = "12 cat st" + +``` +then +```bash +yq '.person.name' sample.toml +``` +will output +```yaml +hello +``` + ## Parse: inline table Given a sample.toml file of: ```toml @@ -88,24 +104,3 @@ suburb: nice ``` -## Parse: with header -Given a sample.toml file of: -```toml - -[servers] - -[servers.alpha] -ip = "10.0.0.1" - -``` -then -```bash -yq -oy '.' sample.toml -``` -will output -```yaml -servers: - alpha: - ip: 10.0.0.1 -``` - diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/yq-4.33.2/pkg/yqlib/encoder_toml.go new/yq-4.33.3/pkg/yqlib/encoder_toml.go --- old/yq-4.33.2/pkg/yqlib/encoder_toml.go 1970-01-01 01:00:00.000000000 +0100 +++ new/yq-4.33.3/pkg/yqlib/encoder_toml.go 2023-04-11 04:06:26.000000000 +0200 @@ -0,0 +1,34 @@ +package yqlib + +import ( + "fmt" + "io" + + yaml "gopkg.in/yaml.v3" +) + +type tomlEncoder struct { +} + +func NewTomlEncoder() Encoder { + return &tomlEncoder{} +} + +func (te *tomlEncoder) Encode(writer io.Writer, node *yaml.Node) error { + if node.Kind == yaml.ScalarNode { + return writeString(writer, node.Value+"\n") + } + return fmt.Errorf("only scalars (e.g. strings, numbers, booleans) are supported for TOML output at the moment. Please use yaml output format (-oy) until the encoder has been fully implemented") +} + +func (te *tomlEncoder) PrintDocumentSeparator(writer io.Writer) error { + return nil +} + +func (te *tomlEncoder) PrintLeadingContent(writer io.Writer, content string) error { + return nil +} + +func (te *tomlEncoder) CanHandleAliases() bool { + return false +} diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/yq-4.33.2/pkg/yqlib/operator_collect.go new/yq-4.33.3/pkg/yqlib/operator_collect.go --- old/yq-4.33.2/pkg/yqlib/operator_collect.go 2023-03-31 01:21:59.000000000 +0200 +++ new/yq-4.33.3/pkg/yqlib/operator_collect.go 2023-04-11 04:06:26.000000000 +0200 @@ -27,6 +27,7 @@ log.Debugf("-- collectOperation") if context.MatchingNodes.Len() == 0 { + log.Debugf("nothing to collect") node := &yaml.Node{Kind: yaml.SequenceNode, Tag: "!!seq", Value: "[]"} candidate := &CandidateNode{Node: node} return context.SingleChildContext(candidate), nil @@ -41,6 +42,7 @@ } if evaluateAllTogether { + log.Debugf("collect together") collectedNode, err := collectTogether(d, context, expressionNode.RHS) if err != nil { return Context{}, err @@ -56,6 +58,8 @@ collectedNode := &yaml.Node{Kind: yaml.SequenceNode, Tag: "!!seq"} collectCandidate := candidate.CreateReplacement(collectedNode) + log.Debugf("collect rhs: %v", expressionNode.RHS.Operation.toString()) + collectExpResults, err := d.GetMatchingNodes(context.SingleChildContext(candidate), expressionNode.RHS) if err != nil { return Context{}, err @@ -66,6 +70,7 @@ log.Debugf("found this: %v", NodeToString(resultC)) collectedNode.Content = append(collectedNode.Content, unwrapDoc(resultC.Node)) } + log.Debugf("done collect rhs: %v", expressionNode.RHS.Operation.toString()) results.PushBack(collectCandidate) } diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/yq-4.33.2/pkg/yqlib/operator_collect_object_test.go new/yq-4.33.3/pkg/yqlib/operator_collect_object_test.go --- old/yq-4.33.2/pkg/yqlib/operator_collect_object_test.go 2023-03-31 01:21:59.000000000 +0200 +++ new/yq-4.33.3/pkg/yqlib/operator_collect_object_test.go 2023-04-11 04:06:26.000000000 +0200 @@ -16,6 +16,13 @@ }, { skipDoc: true, + expression: `({} + {}) | (.b = 3)`, + expected: []string{ + "D0, P[], (!!map)::b: 3\n", + }, + }, + { + skipDoc: true, document: "a: []", expression: `.a += [{"key": "att2", "value": "val2"}]`, expected: []string{ diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/yq-4.33.2/pkg/yqlib/operator_pipe.go new/yq-4.33.3/pkg/yqlib/operator_pipe.go --- old/yq-4.33.2/pkg/yqlib/operator_pipe.go 2023-03-31 01:21:59.000000000 +0200 +++ new/yq-4.33.3/pkg/yqlib/operator_pipe.go 2023-04-11 04:06:26.000000000 +0200 @@ -5,12 +5,12 @@ if expressionNode.LHS.Operation.OperationType == assignVariableOpType { return variableLoop(d, context, expressionNode) } - lhs, err := d.GetMatchingNodes(context, expressionNode.LHS) if err != nil { return Context{}, err } - rhs, err := d.GetMatchingNodes(lhs, expressionNode.RHS) + rhsContext := context.ChildContext(lhs.MatchingNodes) + rhs, err := d.GetMatchingNodes(rhsContext, expressionNode.RHS) if err != nil { return Context{}, err } diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/yq-4.33.2/pkg/yqlib/operator_pipe_test.go new/yq-4.33.3/pkg/yqlib/operator_pipe_test.go --- old/yq-4.33.2/pkg/yqlib/operator_pipe_test.go 2023-03-31 01:21:59.000000000 +0200 +++ new/yq-4.33.3/pkg/yqlib/operator_pipe_test.go 2023-04-11 04:06:26.000000000 +0200 @@ -21,6 +21,14 @@ "D0, P[], (doc)::{a: cat, b: dog, c: same}\n", }, }, + { + skipDoc: true, + description: "Don't pass readonly context", + expression: `(3 + 4) | ({} | .b = "dog")`, + expected: []string{ + "D0, P[], (!!map)::b: dog\n", + }, + }, } func TestPipeOperatorScenarios(t *testing.T) { diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/yq-4.33.2/pkg/yqlib/operator_traverse_path.go new/yq-4.33.3/pkg/yqlib/operator_traverse_path.go --- old/yq-4.33.2/pkg/yqlib/operator_traverse_path.go 2023-03-31 01:21:59.000000000 +0200 +++ new/yq-4.33.3/pkg/yqlib/operator_traverse_path.go 2023-04-11 04:06:26.000000000 +0200 @@ -80,6 +80,8 @@ // BUT we still return the original context back (see jq) // https://stedolan.github.io/jq/manual/#Variable/SymbolicBindingOperator:...as$identifier|... + log.Debugf("--traverseArrayOperator") + if expressionNode.RHS != nil && expressionNode.RHS.RHS != nil && expressionNode.RHS.RHS.Operation.OperationType == createMapOpType { return sliceArrayOperator(d, context, expressionNode.RHS.RHS) } @@ -103,6 +105,8 @@ } var indicesToTraverse = rhs.MatchingNodes.Front().Value.(*CandidateNode).Node.Content + log.Debugf("indicesToTraverse %v", len(indicesToTraverse)) + //now we traverse the result of the lhs against the indices we found result, err := traverseNodesWithArrayIndices(lhs, indicesToTraverse, prefs) if err != nil { @@ -231,7 +235,8 @@ return nil, err } - if !prefs.DontAutoCreate && !context.DontAutoCreate && newMatches.Len() == 0 { + if !splat && !prefs.DontAutoCreate && !context.DontAutoCreate && newMatches.Len() == 0 { + log.Debugf("no matches, creating one") //no matches, create one automagically valueNode := &yaml.Node{Tag: "!!null", Kind: yaml.ScalarNode, Value: "null"} diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/yq-4.33.2/pkg/yqlib/operator_traverse_path_test.go new/yq-4.33.3/pkg/yqlib/operator_traverse_path_test.go --- old/yq-4.33.2/pkg/yqlib/operator_traverse_path_test.go 2023-03-31 01:21:59.000000000 +0200 +++ new/yq-4.33.3/pkg/yqlib/operator_traverse_path_test.go 2023-04-11 04:06:26.000000000 +0200 @@ -36,6 +36,13 @@ var traversePathOperatorScenarios = []expressionScenario{ { + skipDoc: true, + description: "splat empty map", + document: "{}", + expression: ".[]", + expected: []string{}, + }, + { skipDoc: true, document: `[[1]]`, expression: `.[0][0]`, diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/yq-4.33.2/pkg/yqlib/printer.go new/yq-4.33.3/pkg/yqlib/printer.go --- old/yq-4.33.2/pkg/yqlib/printer.go 2023-03-31 01:21:59.000000000 +0200 +++ new/yq-4.33.3/pkg/yqlib/printer.go 2023-04-11 04:06:26.000000000 +0200 @@ -31,6 +31,7 @@ Base64OutputFormat UriOutputFormat ShOutputFormat + TomlOutputFormat ) func OutputFormatFromString(format string) (PrinterOutputFormat, error) { @@ -47,6 +48,8 @@ return TSVOutputFormat, nil case "xml", "x": return XMLOutputFormat, nil + case "toml": + return TomlOutputFormat, nil default: return 0, fmt.Errorf("unknown format '%v' please use [yaml|json|props|csv|tsv|xml]", format) } diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/yq-4.33.2/pkg/yqlib/toml_test.go new/yq-4.33.3/pkg/yqlib/toml_test.go --- old/yq-4.33.2/pkg/yqlib/toml_test.go 2023-03-31 01:21:59.000000000 +0200 +++ new/yq-4.33.3/pkg/yqlib/toml_test.go 2023-04-11 04:06:26.000000000 +0200 @@ -95,6 +95,13 @@ scenarioType: "decode", }, { + description: "Encode: Scalar", + input: "person.name = \"hello\"\nperson.address = \"12 cat st\"\n", + expression: ".person.name", + expected: "hello\n", + scenarioType: "roundtrip", + }, + { skipDoc: true, input: `A.B = "hello"`, expected: "A:\n B: hello\n", @@ -170,6 +177,7 @@ }, { description: "Parse: with header", + skipDoc: true, input: sampleWithHeader, expected: expectedSampleWithHeader, scenarioType: "decode", @@ -187,6 +195,8 @@ } else { test.AssertResultComplexWithContext(t, s.expectedError, err.Error(), s.description) } + case "roundtrip": + test.AssertResultWithContext(t, s.expected, mustProcessFormatScenario(s, NewTomlDecoder(), NewTomlEncoder()), s.description) } } @@ -212,6 +222,28 @@ writeOrPanic(w, fmt.Sprintf("```yaml\n%v```\n\n", mustProcessFormatScenario(s, NewTomlDecoder(), NewYamlEncoder(2, false, ConfiguredYamlPreferences)))) } +func documentTomlRoundtripScenario(w *bufio.Writer, s formatScenario) { + writeOrPanic(w, fmt.Sprintf("## %v\n", s.description)) + + if s.subdescription != "" { + writeOrPanic(w, s.subdescription) + writeOrPanic(w, "\n\n") + } + + writeOrPanic(w, "Given a sample.toml file of:\n") + writeOrPanic(w, fmt.Sprintf("```toml\n%v\n```\n", s.input)) + + writeOrPanic(w, "then\n") + expression := s.expression + if expression == "" { + expression = "." + } + writeOrPanic(w, fmt.Sprintf("```bash\nyq '%v' sample.toml\n```\n", expression)) + writeOrPanic(w, "will output\n") + + writeOrPanic(w, fmt.Sprintf("```yaml\n%v```\n\n", mustProcessFormatScenario(s, NewTomlDecoder(), NewTomlEncoder()))) +} + func documentTomlScenario(t *testing.T, w *bufio.Writer, i interface{}) { s := i.(formatScenario) @@ -221,6 +253,8 @@ switch s.scenarioType { case "", "decode": documentTomlDecodeScenario(w, s) + case "roundtrip": + documentTomlRoundtripScenario(w, s) default: panic(fmt.Sprintf("unhandled scenario type %q", s.scenarioType)) diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/yq-4.33.2/release_notes.txt new/yq-4.33.3/release_notes.txt --- old/yq-4.33.2/release_notes.txt 2023-03-31 01:21:59.000000000 +0200 +++ new/yq-4.33.3/release_notes.txt 2023-04-11 04:06:26.000000000 +0200 @@ -1,3 +1,15 @@ +4.33.3: + - Fixed bug when splatting empty array #1613 + - Added scalar output for TOML (#1617) + - Fixed passing of readonly context in pipe (partial fix for #1631) + - Bumped dependency versions + +4.33.2: + - Add ``--nul-output|-0`` flag to separate element with NUL character (#1550) Thanks @vaab! + - Add removable-media interface plug declaration to the snap packaging(#1618) Thanks @brlin-tw! + - Scalar output now handled in csv, tsv and property files + - Bumped dependency versions + 4.33.1: - Added read-only TOML support! #1364. Thanks @pelletier for making your API available in your toml lib :) - Added warning when auto detect by file type is outputs JSON (#1608) diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/yq-4.33.2/snap/snapcraft.yaml new/yq-4.33.3/snap/snapcraft.yaml --- old/yq-4.33.2/snap/snapcraft.yaml 2023-03-31 01:21:59.000000000 +0200 +++ new/yq-4.33.3/snap/snapcraft.yaml 2023-04-11 04:06:26.000000000 +0200 @@ -1,5 +1,5 @@ name: yq -version: 'v4.33.2' +version: 'v4.33.3' summary: A lightweight and portable command-line YAML processor description: | The aim of the project is to be the jq or sed of yaml files.