refactor: simplify flag system and extract to internal/flag

Replace complex ptrVal/Val/Flag type machinery with direct pflag
calls. Move flag logic and interactive wizard to internal/flag
package. Eliminate ~200 lines of flag boilerplate.

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
This commit is contained in:
JiXieShi
2026-05-23 21:52:40 +08:00
parent a1524a7e17
commit 65c1a48f10
4 changed files with 266 additions and 528 deletions
+6 -7
View File
@@ -11,15 +11,14 @@ import (
"strconv"
"strings"
"github.com/jixishi/SerialTerminalForWindowsTerminal/internal/flag"
"github.com/jixishi/SerialTerminalForWindowsTerminal/internal/session"
"golang.org/x/term"
)
func init() {
log.SetFlags(log.Ldate | log.Ltime | log.Lshortfile | log.Lmsgprefix)
for _, f := range flags {
flagInit(&f)
}
flag.Init(cfg)
}
func main() {
@@ -30,16 +29,16 @@ func main() {
}
}()
normalizeFlags()
flag.Normalize()
pflag.Parse()
flagExt()
flag.Ext(cfg)
if cfg.PortName == "" {
getCliFlag()
flag.GetCliFlag(cfg)
}
ports, err := session.CheckPortAvailability(cfg.PortName)
if err != nil {
fmt.Println(err)
printUsage(ports)
flag.PrintUsage(ports)
os.Exit(0)
}