mirror of
https://github.com/larksuite/cli.git
synced 2026-07-08 18:13:01 +08:00
refactor(sheets): drop unused int64 flag-type plumbing
No sheets flag-def declares an int64 type and RuntimeContext.Int64 had zero callers, so remove the premature support: the RuntimeContext.Int64 helper, the registerShortcutFlagsWithContext int64 branch, the flagView Int64 method + mapFlagView impl, and the typedDefault/validateRawTypes int64 cases. float64 (consumed by --font-size) is kept.
This commit is contained in:
@@ -210,12 +210,6 @@ func (ctx *RuntimeContext) Int(name string) int {
|
||||
return v
|
||||
}
|
||||
|
||||
// Int64 returns an int64 flag value.
|
||||
func (ctx *RuntimeContext) Int64(name string) int64 {
|
||||
v, _ := ctx.Cmd.Flags().GetInt64(name)
|
||||
return v
|
||||
}
|
||||
|
||||
// Float64 returns a float64 flag value (non-integer numbers).
|
||||
func (ctx *RuntimeContext) Float64(name string) float64 {
|
||||
v, _ := ctx.Cmd.Flags().GetFloat64(name)
|
||||
@@ -1087,10 +1081,6 @@ func registerShortcutFlagsWithContext(ctx context.Context, cmd *cobra.Command, f
|
||||
var d int
|
||||
fmt.Sscanf(fl.Default, "%d", &d)
|
||||
cmd.Flags().Int(fl.Name, d, desc)
|
||||
case "int64":
|
||||
var d int64
|
||||
fmt.Sscanf(fl.Default, "%d", &d)
|
||||
cmd.Flags().Int64(fl.Name, d, desc)
|
||||
case "float64":
|
||||
var d float64
|
||||
fmt.Sscanf(fl.Default, "%g", &d)
|
||||
|
||||
@@ -18,7 +18,7 @@ const (
|
||||
// Flag describes a CLI flag for a shortcut.
|
||||
type Flag struct {
|
||||
Name string // flag name (e.g. "calendar-id")
|
||||
Type string // "string" (default) | "bool" | "int" | "int64" | "float64" | "string_array" | "string_slice"
|
||||
Type string // "string" (default) | "bool" | "int" | "float64" | "string_array" | "string_slice"
|
||||
Default string // default value as string
|
||||
Desc string // help text
|
||||
Hidden bool // hidden from --help, still readable at runtime
|
||||
|
||||
@@ -21,7 +21,6 @@ import (
|
||||
type flagView interface {
|
||||
Str(name string) string
|
||||
Int(name string) int
|
||||
Int64(name string) int64
|
||||
Float64(name string) float64
|
||||
Bool(name string) bool
|
||||
StrArray(name string) []string
|
||||
@@ -90,10 +89,6 @@ func typedDefault(df flagDef) interface{} {
|
||||
var n int
|
||||
fmt.Sscanf(df.Default, "%d", &n)
|
||||
return n
|
||||
case "int64":
|
||||
var n int64
|
||||
fmt.Sscanf(df.Default, "%d", &n)
|
||||
return n
|
||||
case "float64":
|
||||
var f float64
|
||||
fmt.Sscanf(df.Default, "%g", &f)
|
||||
@@ -175,22 +170,6 @@ func (m mapFlagView) Int(name string) int {
|
||||
return 0
|
||||
}
|
||||
|
||||
func (m mapFlagView) Int64(name string) int64 {
|
||||
v, ok := m.lookup(name)
|
||||
if !ok {
|
||||
return 0
|
||||
}
|
||||
switch t := v.(type) {
|
||||
case float64:
|
||||
return int64(t)
|
||||
case int:
|
||||
return int64(t)
|
||||
case int64:
|
||||
return t
|
||||
}
|
||||
return 0
|
||||
}
|
||||
|
||||
func (m mapFlagView) Float64(name string) float64 {
|
||||
v, ok := m.lookup(name)
|
||||
if !ok {
|
||||
@@ -257,7 +236,7 @@ func (m mapFlagView) Changed(name string) bool {
|
||||
|
||||
// validateRawTypes rejects sub-op input fields whose JSON type contradicts the
|
||||
// flag's declared type in flag-defs. +batch-update skips parse-time schema
|
||||
// validation for `operations`, and Int/Int64/Float64/Bool silently fall back to
|
||||
// validation for `operations`, and Int/Float64/Bool silently fall back to
|
||||
// the zero value on a type mismatch — so without this guard a wrong-typed scalar
|
||||
// (e.g. "index":"abc" or "multiple":"true") would land as 0 / false instead of
|
||||
// erroring, writing to the wrong place. Only numeric and boolean flags are
|
||||
@@ -294,7 +273,7 @@ func (m mapFlagView) validateRawTypes() error {
|
||||
continue // unknown key — leave it for the translator / schema layer
|
||||
}
|
||||
switch typ {
|
||||
case "int", "int64", "float64":
|
||||
case "int", "float64":
|
||||
if _, isNum := val.(float64); !isNum {
|
||||
return fmt.Errorf("--%s must be a number, got %s", name, jsonTypeName(val))
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user