Skip to content

feat(core): add Cobra CLI entrypoint#665

Open
caorushizi wants to merge 1 commit into
masterfrom
codex/core-cobra-cli
Open

feat(core): add Cobra CLI entrypoint#665
caorushizi wants to merge 1 commit into
masterfrom
codex/core-cobra-cli

Conversation

@caorushizi

Copy link
Copy Markdown
Collaborator

Summary

  • add a separate Go Cobra CLI entrypoint under apps/core/cmd/cli
  • move shared core startup/config/runtime wiring into internal/app
  • keep cmd/server focused on HTTP API server startup

Tests

  • go test ./internal/app ./cmd/cli ./internal/core ./pkg/conf
  • go test ./cmd/server with temporary assets/player embed placeholder
  • go run ./cmd/cli --help
  • go run ./cmd/cli download --help

Copilot AI review requested due to automatic review settings May 16, 2026 19:38
@changeset-bot

changeset-bot Bot commented May 16, 2026

Copy link
Copy Markdown

⚠️ No Changeset found

Latest commit: d654368

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 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".

Comment on lines +165 to +169
cfg.Proxy = s.Proxy
cfg.UseProxy = s.UseProxy
cfg.DeleteSegments = s.DeleteSegments
if s.MaxRunner > 0 {
cfg.MaxRunner = s.MaxRunner

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge 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 👍 / 👎.

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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/cli with a download <url> command.
  • Moves shared app config, app store defaults, logger/runtime initialization, downloader queue, task logs, and DB setup into internal/app.
  • Refactors cmd/server to 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.

Comment on lines +103 to +107
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)
}
Comment thread apps/core/cmd/cli/main.go
Comment on lines +118 to +122
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")
Comment thread apps/core/cmd/cli/main.go
Comment on lines +82 to +87
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
Comment thread apps/core/cmd/cli/main.go
Comment on lines +20 to +22
if err := newRootCommand().Execute(); err != nil {
fmt.Fprintln(os.Stderr, err)
os.Exit(1)
Comment on lines +155 to +168
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 {
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants