MCPcopy Create free account
hub / github.com/chainreactors/EvilProxy / main

Function main

cmd/fetch_codex_models/main.go:56–163  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

54}
55
56func main() {
57 var authsDir string
58 var configPath string
59 var outputPath string
60 var clientVersion string
61 var pretty bool
62
63 flag.StringVar(&authsDir, "auths-dir", "", "Directory containing auth JSON files (overrides config auth-dir)")
64 flag.StringVar(&configPath, "config", "", "Configure File Path")
65 flag.StringVar(&outputPath, "output", "codex_models.json", "Output JSON file path")
66 flag.StringVar(&clientVersion, "client-version", defaultClientVersion, "Codex client_version query value")
67 flag.BoolVar(&pretty, "pretty", true, "Pretty-print the output JSON")
68 flag.Parse()
69 authsDirOverridden := false
70 flag.Visit(func(f *flag.Flag) {
71 if f.Name == "auths-dir" {
72 authsDirOverridden = true
73 }
74 })
75
76 wd, err := os.Getwd()
77 if err != nil {
78 fmt.Fprintf(os.Stderr, "error: cannot get working directory: %v\n", err)
79 os.Exit(1)
80 }
81
82 if strings.TrimSpace(configPath) == "" {
83 configPath = filepath.Join(wd, "config.yaml")
84 }
85 cfg, err := config.LoadConfigOptional(configPath, false)
86 if err != nil {
87 fmt.Fprintf(os.Stderr, "error: failed to load config file %s: %v\n", configPath, err)
88 os.Exit(1)
89 }
90 if cfg == nil {
91 cfg = &config.Config{}
92 }
93
94 if !authsDirOverridden {
95 authsDir = cfg.AuthDir
96 } else if strings.TrimSpace(authsDir) != "" && !strings.HasPrefix(strings.TrimSpace(authsDir), "~") && !filepath.IsAbs(authsDir) {
97 authsDir = filepath.Join(wd, authsDir)
98 }
99 if authsDir, err = util.ResolveAuthDir(authsDir); err != nil {
100 fmt.Fprintf(os.Stderr, "error: failed to resolve auth directory: %v\n", err)
101 os.Exit(1)
102 }
103 if !filepath.IsAbs(outputPath) {
104 outputPath = filepath.Join(wd, outputPath)
105 }
106
107 fmt.Printf("Scanning auth files in: %s\n", authsDir)
108
109 fileStore := sdkauth.NewFileTokenStore()
110 fileStore.SetBaseDir(authsDir)
111
112 ctx := context.Background()
113 auths, err := fileStore.List(ctx)

Callers

nothing calls this directly

Calls 8

SetBaseDirMethod · 0.95
ListMethod · 0.95
LoadConfigOptionalFunction · 0.92
ResolveAuthDirFunction · 0.92
findCodexAuthFunction · 0.85
ensureAccessTokenFunction · 0.85
fetchModelsFunction · 0.70
prettyJSONFunction · 0.70

Tested by

no test coverage detected