add -- args passing from shell as const args in query - #7364
Merged
Merged
Conversation
nwt
approved these changes
Sep 28, 2026
Member
There was a problem hiding this comment.
Nit: Although this tests code in compiler/parser, it's more a test of the super command than the parser itself, so cmd/super/ztests feels like a more natural home.
| path = append(path, component) | ||
| parent = cmd | ||
| if err := flags.Parse(args); err != nil { | ||
| if err := flags.Parse(escape(args)); err != nil { |
Member
There was a problem hiding this comment.
Maybe do this without escape and unescape (which won't do the right thing in the unlikely event that one of the arguments is "\x00--")?
--- a/pkg/charm/instance.go
+++ b/pkg/charm/instance.go
@@ -3,6 +3,7 @@ package charm
import (
"flag"
"fmt"
+ "slices"
"sort"
"strings"
)
@@ -77,9 +78,15 @@ func parse(spec *Spec, args []string, parent Command, interiorLeaf int) (path, [
}
path = append(path, component)
parent = cmd
- if err := flags.Parse(escape(args)); err != nil {
+ savedArgs := args
+ var dashDashArgs []string
+ if k := slices.Index(args, "--"); k >= 0 {
+ dashDashArgs = args[k:]
+ args = args[:k]
+ }
+ if err := flags.Parse(args); err != nil {
if usage {
- s := strings.Join(args, " ")
+ s := strings.Join(savedArgs, " ")
err = fmt.Errorf("at flag: %q: %w", s, err)
}
return path, nil, false, err
@@ -87,7 +94,7 @@ func parse(spec *Spec, args []string, parent Command, interiorLeaf int) (path, [
if help {
return path, nil, hidden, NeedHelp
}
- rest := unescape(flags.Args())
+ rest := append(flags.Args(), dashDashArgs...)
if len(rest) != 0 {
spec = component.spec.lookupSub(rest[0])
if spec != nil {
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #2223