Files
agent-lib/internal/cli/update.go
T

67 lines
1.7 KiB
Go
Raw Normal View History

package cli
import (
"fmt"
"github.com/spf13/cobra"
"github.com/m3tam3re/agent-lib/internal/vendor"
)
func newVendorUpdateCmd() *cobra.Command {
var all bool
cmd := &cobra.Command{
Use: "update [<name>]",
Short: "Fetch the latest revision of the pinned ref and rewrite the external area",
Args: cobra.MaximumNArgs(1),
RunE: func(cmd *cobra.Command, args []string) error {
if all {
if len(args) != 0 {
return fmt.Errorf("--all takes no source name")
}
if err := vendor.UpdateAll(".", cmd.OutOrStdout()); err != nil {
return fmt.Errorf("vendor update: %w", err)
}
return nil
}
if len(args) != 1 {
return fmt.Errorf("specify a source name or --all")
}
if _, err := vendor.Update(".", args[0], cmd.OutOrStdout()); err != nil {
return fmt.Errorf("vendor update: %w", err)
}
return nil
},
}
cmd.Flags().BoolVar(&all, "all", false, "update every source and report per source")
return cmd
}
func newVendorDiffCmd() *cobra.Command {
return &cobra.Command{
Use: "diff <name>",
Short: "Compare upstream against the current selection without modifying anything",
Args: cobra.ExactArgs(1),
RunE: func(cmd *cobra.Command, args []string) error {
if _, err := vendor.Diff(".", args[0], cmd.OutOrStdout()); err != nil {
return fmt.Errorf("vendor diff: %w", err)
}
return nil
},
}
}
func newVendorRemoveCmd() *cobra.Command {
return &cobra.Command{
Use: "remove <name>",
Short: "Delete a source's external area and lockfile entry",
Args: cobra.ExactArgs(1),
RunE: func(cmd *cobra.Command, args []string) error {
if err := vendor.Remove(".", args[0], cmd.OutOrStdout()); err != nil {
return fmt.Errorf("vendor remove: %w", err)
}
return nil
},
}
}