chore: 初始化仓库,导入项目基线代码
Academy v0.8.3 完整代码基线:Go 后端(internal/cmd/cli/mcp-server/docreader)、 Vue 前端(frontend)、数据库迁移(migrations)、部署编排(docker/helm/deploy)与文档。 今日开发的培训推送管理改动随后单独提交。
This commit is contained in:
commit
7ec21f35b0
5767 files changed
+1436788
No files matched your search
@@ -0,0 +1,87 @@
|
||||
package modelcmd
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
|
||||
"github.com/spf13/cobra"
|
||||
|
||||
"academy/cli/internal/cmdutil"
|
||||
"academy/cli/internal/iostreams"
|
||||
sdk "academy/client"
|
||||
)
|
||||
|
||||
// DeleteService is the narrow SDK surface this command depends on.
|
||||
type DeleteService interface {
|
||||
DeleteModel(ctx context.Context, id string) error
|
||||
}
|
||||
|
||||
type deleteOptions struct {
|
||||
Yes bool
|
||||
DryRun bool
|
||||
}
|
||||
|
||||
// NewCmdDelete builds `academy model delete <model-id>`.
|
||||
func NewCmdDelete(f *cmdutil.Factory) *cobra.Command {
|
||||
opts := &deleteOptions{}
|
||||
cmd := &cobra.Command{
|
||||
Use: "delete <model-id>",
|
||||
Short: "Delete a model",
|
||||
Long: `Delete a model by id. High-risk write: without -y/--yes in a non-TTY / JSON
|
||||
context it exits 10 (input.confirmation_required) without deleting. A KB or
|
||||
agent still referencing the model will fail until repointed.`,
|
||||
Args: cobra.ExactArgs(1),
|
||||
RunE: func(c *cobra.Command, args []string) error {
|
||||
fopts, err := cmdutil.CheckFormatFlag(c)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
fopts.ResolveDefault(iostreams.IO.IsStdoutTTY())
|
||||
opts.Yes, _ = c.Flags().GetBool("yes")
|
||||
id := args[0]
|
||||
if handled, err := cmdutil.HandleDryRun(c, opts.DryRun, cmdutil.DryRunPlan{
|
||||
Action: "model.delete",
|
||||
Args: map[string]any{"model": id},
|
||||
}); handled {
|
||||
return err
|
||||
}
|
||||
cli, err := f.Client()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if err := cmdutil.ConfirmDestructive(f.Prompter(), opts.Yes, fopts.WantsJSON(),
|
||||
"delete", "model", id, "model.delete", []string{"academy", "model", "delete", id, "-y"}); err != nil {
|
||||
return err
|
||||
}
|
||||
return runDelete(c.Context(), fopts, cli, id)
|
||||
},
|
||||
}
|
||||
cmdutil.AddFormatFlag(cmd, "id", "deleted")
|
||||
cmdutil.AddDryRunFlag(cmd, &opts.DryRun)
|
||||
cmdutil.SetRisk(cmd, "model.delete")
|
||||
cmdutil.SetAgentHelp(cmd, cmdutil.AgentHelp{
|
||||
UsedFor: "delete a model by id",
|
||||
RequiredFlags: []string{"<model-id> (positional)"},
|
||||
Examples: []string{"academy model delete model_abc -y"},
|
||||
Output: "envelope.data is {id, deleted:true}",
|
||||
Warnings: []string{
|
||||
"Requires explicit user approval (exit 10 / input.confirmation_required); never auto-add -y.",
|
||||
"A knowledge base or agent still referencing this model will fail until repointed.",
|
||||
},
|
||||
})
|
||||
return cmd
|
||||
}
|
||||
|
||||
func runDelete(ctx context.Context, fopts *cmdutil.FormatOptions, svc DeleteService, id string) error {
|
||||
if err := svc.DeleteModel(ctx, id); err != nil {
|
||||
return cmdutil.WrapHTTP(err, "delete model %q", id)
|
||||
}
|
||||
if fopts.WantsJSON() {
|
||||
return fopts.Emit(iostreams.IO.Out, map[string]any{"id": id, "deleted": true}, nil)
|
||||
}
|
||||
fmt.Fprintf(iostreams.IO.Out, "✓ Deleted model %s\n", id)
|
||||
return nil
|
||||
}
|
||||
|
||||
// compile-time check: the production SDK client implements DeleteService.
|
||||
var _ DeleteService = (*sdk.Client)(nil)
|
||||
Reference in new issue
Block a user