feat(core): add Cobra CLI entrypoint#665
Conversation
|
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: d654368290
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| cfg.Proxy = s.Proxy | ||
| cfg.UseProxy = s.UseProxy | ||
| cfg.DeleteSegments = s.DeleteSegments | ||
| if s.MaxRunner > 0 { | ||
| cfg.MaxRunner = s.MaxRunner |
There was a problem hiding this comment.
Honor CLI flags over persisted app-store settings
NewRuntime now unconditionally copies proxy, useProxy, deleteSegments, and maxRunner from persisted app-store state into cfg, which overwrites values already parsed from CLI flags. In the new Cobra entrypoint (cmd/cli), this makes options like --proxy, --use-proxy, --delete-segments, and --max-runner ineffective whenever a user has prior saved config, so one-off CLI overrides silently do not apply.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Pull request overview
Adds a Cobra-based CLI entrypoint for MediaGo core downloads while extracting shared startup/config/runtime wiring into internal/app so the HTTP server and CLI can reuse it.
Changes:
- Introduces
cmd/cliwith adownload <url>command. - Moves shared app config, app store defaults, logger/runtime initialization, downloader queue, task logs, and DB setup into
internal/app. - Refactors
cmd/serverto use the shared runtime and keeps server startup focused on HTTP serving.
AI-generated suggestions may contain errors; use your own judgment when applying them.
Reviewed changes
Copilot reviewed 7 out of 8 changed files in this pull request and generated 5 comments.
Show a summary per file
| File | Description |
|---|---|
apps/core/internal/app/runtime.go |
Adds shared runtime initialization and config/app-store synchronization. |
apps/core/internal/app/config.go |
Adds shared startup configuration defaults and env/default application. |
apps/core/internal/app/appstore.go |
Moves the typed persisted app store model into the shared app package. |
apps/core/cmd/cli/main.go |
Adds the Cobra CLI root and direct download command. |
apps/core/cmd/server/main.go |
Refactors server startup to use internal/app.Runtime. |
apps/core/cmd/server/appstore.go |
Removes server-local app store definitions now moved to internal/app. |
apps/core/go.mod |
Adds Cobra/pflag dependencies and promotes crypto to a direct dependency. |
apps/core/go.sum |
Adds checksums for the new CLI dependencies. |
| appStore.OnDidChange("useProxy", func(newVal, oldVal any) { | ||
| if v, ok := newVal.(bool); ok { | ||
| cfg.SetUseProxy(v) | ||
| logger.Infof("useProxy updated to %v via config change", v) | ||
| } |
| func addConfigFlags(flags *pflag.FlagSet, cfg *app.AppConfig) { | ||
| flags.StringVar(&cfg.LogLevel, "log-level", cfg.LogLevel, "Log level (debug/info/warn/error)") | ||
| flags.StringVar(&cfg.LogDir, "log-dir", cfg.LogDir, "Log directory") | ||
| flags.StringVar(&cfg.DepsDir, "deps-dir", cfg.DepsDir, "Directory containing downloader tool binaries") | ||
| flags.StringVar(&cfg.SchemaPath, "schema-path", cfg.SchemaPath, "Path to the download schema config.json") |
| fmt.Printf("Starting %s download: %s\n", params.Type, params.Name) | ||
| err = rt.Downloader.Download(ctx, params, core.Callbacks{ | ||
| OnProgress: func(e core.ProgressEvent) { | ||
| percent := int(e.Percent) | ||
| if percent != lastPercent { | ||
| lastPercent = percent |
| if err := newRootCommand().Execute(); err != nil { | ||
| fmt.Fprintln(os.Stderr, err) | ||
| os.Exit(1) |
| func syncAppStoreToCfg(store *conf.Conf[AppStore], cfg *AppConfig) { | ||
| s := store.Store() | ||
| cliLocalDir := cfg.LocalDir | ||
| cliExplicit := cliLocalDir != "" && cliLocalDir != "./downloads" | ||
|
|
||
| if cliExplicit { | ||
| _ = store.Set("local", cliLocalDir) | ||
| } else if s.Local != "" { | ||
| cfg.LocalDir = s.Local | ||
| } | ||
| cfg.Proxy = s.Proxy | ||
| cfg.UseProxy = s.UseProxy | ||
| cfg.DeleteSegments = s.DeleteSegments | ||
| if s.MaxRunner > 0 { |
Summary
Tests