Skip to content

Commit

Permalink
removed inline comments
Browse files Browse the repository at this point in the history
  • Loading branch information
simonmittag committed Jun 16, 2023
1 parent 9a512e1 commit 97ec55f
Showing 1 changed file with 0 additions and 11 deletions.
11 changes: 0 additions & 11 deletions cmd/punycoder/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,33 +60,22 @@ func parseHost(args []string) string {
return host
}

// ParseFlags parses the command line args, allowing flags to be
// specified after positional args.
func parseFlags() error {
return parseFlagSet(flag.CommandLine, os.Args[1:])
}

// ParseFlagSet works like flagset.Parse(), except positional arguments are not
// required to come after flag arguments.
func parseFlagSet(flagset *flag.FlagSet, args []string) error {
var positionalArgs []string
for {
if err := flagset.Parse(args); err != nil {
return err
}
// Consume all the flags that were parsed as flags.
args = args[len(args)-flagset.NArg():]
if len(args) == 0 {
break
}
// There's at least one flag remaining and it must be a positional arg since
// we consumed all args that were parsed as flags. Consume just the first
// one, and retry parsing, since subsequent args may be flags.
positionalArgs = append(positionalArgs, args[0])
args = args[1:]
}
// Parse just the positional args so that flagset.Args()/flagset.NArgs()
// return the expected value.
// Note: This should never return an error.
return flagset.Parse(positionalArgs)
}

0 comments on commit 97ec55f

Please sign in to comment.