Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

how to get flag self position in os.Args #2010

Open
zhujintao opened this issue Nov 21, 2024 · 5 comments
Open

how to get flag self position in os.Args #2010

zhujintao opened this issue Nov 21, 2024 · 5 comments
Labels
area/v2 relates to / is being considered for v2 kind/question someone asking a question status/triage maintainers still need to look into this

Comments

@zhujintao
Copy link

how to get flag self position in os.Args

@zhujintao zhujintao added area/v2 relates to / is being considered for v2 kind/question someone asking a question status/triage maintainers still need to look into this labels Nov 21, 2024
@dearchap
Copy link
Contributor

@zhujintao Can you elaborate with an example ?

@zhujintao
Copy link
Author

mask password field in command lineps -ef --mysql-dsn=*********

flag := &cli.StringFlag{Name: "mysql-dsn", Usage: "mysql connect dsn, format: user:password@ip:port` `"}
	flag.Action = func(ctx context.Context, cli *cli.Command, s string) error {

		var pos int
		for _, name := range flag.Names() {
			findname := "--" + name + "=" + s
			pos = slices.Index(os.Args, s)
			if pos == -1 {
				pos = slices.Index(os.Args, findname)
			}
		}

                 // mask password args to **** 
                 maskDsnPasswordForIndex(pos)
	  
                 return nil
	}

@dearchap
Copy link
Contributor

@zhujintao No we dont have any mechanism for the feature you want. You could reconstruct the command line args based on all the flags currently set and mask specific stuff

@zhujintao
Copy link
Author

ok, can add method to get field position in command line?

@dearchap
Copy link
Contributor

If you'd like to add it I would be happy to review your PR.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/v2 relates to / is being considered for v2 kind/question someone asking a question status/triage maintainers still need to look into this
Projects
None yet
Development

No branches or pull requests

2 participants