2026-08-23 10:31:00 +02:00
|
|
|
package cli
|
|
|
|
|
|
|
|
|
|
import (
|
|
|
|
|
"fmt"
|
|
|
|
|
|
|
|
|
|
"github.com/spf13/cobra"
|
|
|
|
|
|
|
|
|
|
"github.com/m3tam3re/agent-lib/internal/client"
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
func newSyncCmd() *cobra.Command {
|
2026-08-23 15:08:27 +02:00
|
|
|
var configPath, repoURL, ref string
|
2026-10-02 12:34:57 +02:00
|
|
|
var force bool
|
2026-08-23 10:31:00 +02:00
|
|
|
cmd := &cobra.Command{
|
|
|
|
|
Use: "sync",
|
|
|
|
|
Short: "Pull the work repository and deploy its content to OpenCode",
|
2026-08-23 15:08:27 +02:00
|
|
|
Long: "Pulls the work repository and deploys skills, commands and agents " +
|
|
|
|
|
"into the OpenCode runtime paths. The repository comes from --repo, " +
|
|
|
|
|
"or from the config chain: --config, " + client.ConfigEnv + " env, the " +
|
|
|
|
|
"user-level config, or the admin-protected platform default. " +
|
2026-10-02 12:34:57 +02:00
|
|
|
"Idempotent: re-running changes nothing when content and disk match. " +
|
|
|
|
|
"Locally modified managed items are kept by default (skip + warn); " +
|
|
|
|
|
"--force overwrites them with the repository version and removes " +
|
|
|
|
|
"them after upstream deletion. Unmanaged items are never touched.",
|
2026-08-23 10:31:00 +02:00
|
|
|
Args: cobra.NoArgs,
|
|
|
|
|
RunE: func(cmd *cobra.Command, args []string) error {
|
2026-10-02 12:34:57 +02:00
|
|
|
opts := client.SyncOptions{ConfigPath: configPath, RepoURL: repoURL, Ref: ref, Force: force}
|
2026-08-23 15:08:27 +02:00
|
|
|
if _, err := client.Sync(opts, cmd.OutOrStdout()); err != nil {
|
2026-08-23 10:31:00 +02:00
|
|
|
return fmt.Errorf("sync: %w", err)
|
|
|
|
|
}
|
|
|
|
|
return nil
|
|
|
|
|
},
|
|
|
|
|
}
|
2026-08-23 15:08:27 +02:00
|
|
|
cmd.Flags().StringVar(&configPath, "config", "", "client config path (default: "+client.ConfigEnv+" env, user config, or platform default)")
|
|
|
|
|
cmd.Flags().StringVar(&repoURL, "repo", "", "work repository URL or path — overrides any config, works without one")
|
|
|
|
|
cmd.Flags().StringVar(&ref, "ref", "", "branch or tag to pull (requires --repo)")
|
2026-10-02 12:34:57 +02:00
|
|
|
cmd.Flags().BoolVar(&force, "force", false, "overwrite locally modified managed items with the repository version; unmanaged items are never touched")
|
2026-08-23 10:31:00 +02:00
|
|
|
return cmd
|
|
|
|
|
}
|