Skip to content

add -- args passing from shell as const args in query - #7364

Merged
mccanne merged 2 commits into
mainfrom
command-args
Sep 28, 2026
Merged

mccanne merged 2 commits into
mainfrom
command-args

Conversation

@mccanne

@mccanne mccanne commented Sep 28, 2026

Copy link
Copy Markdown
Collaborator

Closes #2223

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Comment thread pkg/charm/instance.go Outdated
path = append(path, component)
parent = cmd
if err := flags.Parse(args); err != nil {
if err := flags.Parse(escape(args)); err != nil {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 {

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

cool

@mccanne
mccanne merged commit ec6168d into main Sep 28, 2026
4 checks passed
@mccanne
mccanne deleted the command-args branch September 28, 2026 21:22
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add mechanism to pass external arguments into a query

2 participants