Fix Conversion Flag Entry
This commit is contained in:
@@ -107,6 +107,7 @@ func printConvertUsage(stdout io.Writer) {
|
||||
_, _ = fmt.Fprintln(stdout, "2da-to-module notes:")
|
||||
_, _ = fmt.Fprintln(stdout, " - --namespace is optional when topdata/templates/config.json declares it for the input table")
|
||||
_, _ = fmt.Fprintln(stdout, " - --name controls inferred output naming: add_<namespace>_<name>.json")
|
||||
_, _ = fmt.Fprintln(stdout, " - flags accept both --flag value and --flag=value forms")
|
||||
_, _ = fmt.Fprintln(stdout, " - unkeyed rows now fail conversion instead of being skipped")
|
||||
}
|
||||
|
||||
@@ -164,6 +165,40 @@ func parseConvertArgs(args []string, allowFormat bool, defaultCollision string)
|
||||
}
|
||||
opts.Type = args[index]
|
||||
default:
|
||||
if value, ok := parseInlineFlagValue(arg, "--namespace"); ok {
|
||||
opts.Namespace = value
|
||||
continue
|
||||
}
|
||||
if value, ok := parseInlineFlagValue(arg, "--key-field"); ok {
|
||||
opts.KeyFields = append(opts.KeyFields, value)
|
||||
continue
|
||||
}
|
||||
if value, ok := parseInlineFlagValue(arg, "--name"); ok {
|
||||
opts.Name = value
|
||||
continue
|
||||
}
|
||||
if value, ok := parseInlineFlagValue(arg, "--collision"); ok {
|
||||
opts.CollisionMode = value
|
||||
continue
|
||||
}
|
||||
if value, ok := parseInlineFlagValue(arg, "--base-dialog"); ok {
|
||||
opts.BaseDialog = value
|
||||
continue
|
||||
}
|
||||
if value, ok := parseInlineFlagValue(arg, "--format"); ok {
|
||||
if !allowFormat {
|
||||
return opts, "", "", fmt.Errorf("%s does not accept %s", positionalSafe(args), "--format")
|
||||
}
|
||||
opts.Type = value
|
||||
continue
|
||||
}
|
||||
if value, ok := parseInlineFlagValue(arg, "--type"); ok {
|
||||
if !allowFormat {
|
||||
return opts, "", "", fmt.Errorf("%s does not accept %s", positionalSafe(args), "--type")
|
||||
}
|
||||
opts.Type = value
|
||||
continue
|
||||
}
|
||||
if strings.HasPrefix(arg, "--") {
|
||||
return opts, "", "", fmt.Errorf("unknown flag %q", arg)
|
||||
}
|
||||
@@ -243,6 +278,14 @@ func parseConvertArgs(args []string, allowFormat bool, defaultCollision string)
|
||||
return opts, positional[0], positional[1], nil
|
||||
}
|
||||
|
||||
func parseInlineFlagValue(arg, name string) (string, bool) {
|
||||
prefix := name + "="
|
||||
if !strings.HasPrefix(arg, prefix) {
|
||||
return "", false
|
||||
}
|
||||
return strings.TrimSpace(arg[len(prefix):]), true
|
||||
}
|
||||
|
||||
func positionalSafe(args []string) string {
|
||||
if len(args) == 0 {
|
||||
return "command"
|
||||
|
||||
Reference in New Issue
Block a user