diff --git a/cmd/repo.go b/cmd/repo.go index 428408ea..f1bc3395 100644 --- a/cmd/repo.go +++ b/cmd/repo.go @@ -14,6 +14,7 @@ func makeCmdRepo() *commander.Command { makeCmdRepoCopy(), makeCmdRepoCreate(), makeCmdRepoDrop(), + makeCmdRepoEdit(), makeCmdRepoImport(), makeCmdRepoList(), makeCmdRepoMove(), diff --git a/cmd/repo_edit.go b/cmd/repo_edit.go new file mode 100644 index 00000000..b2f1531f --- /dev/null +++ b/cmd/repo_edit.go @@ -0,0 +1,68 @@ +package cmd + +import ( + "fmt" + "github.com/gonuts/commander" + "github.com/gonuts/flag" +) + +func aptlyRepoEdit(cmd *commander.Command, args []string) error { + var err error + if len(args) != 1 { + cmd.Usage() + return err + } + + repo, err := context.collectionFactory.LocalRepoCollection().ByName(args[0]) + if err != nil { + return fmt.Errorf("unable to edit: %s", err) + } + + err = context.collectionFactory.LocalRepoCollection().LoadComplete(repo) + if err != nil { + return fmt.Errorf("unable to edit: %s", err) + } + + if cmd.Flag.Lookup("comment").Value.String() != "" { + repo.Comment = cmd.Flag.Lookup("comment").Value.String() + } + + if cmd.Flag.Lookup("distribution").Value.String() != "" { + repo.DefaultDistribution = cmd.Flag.Lookup("distribution").Value.String() + } + + if cmd.Flag.Lookup("component").Value.String() != "" { + repo.DefaultComponent = cmd.Flag.Lookup("component").Value.String() + } + + err = context.collectionFactory.LocalRepoCollection().Update(repo) + if err != nil { + return fmt.Errorf("unable to edit: %s", err) + } + + fmt.Printf("Local repo %s successfully updated.\n", repo) + return err +} + +func makeCmdRepoEdit() *commander.Command { + cmd := &commander.Command{ + Run: aptlyRepoEdit, + UsageLine: "edit ", + Short: "edit properties of local repository", + Long: ` +Command edit allows to change metadata of local repository: +comment, default distribution and component. + +Example: + + $ aptly repo edit -distribution=wheezy testing +`, + Flag: *flag.NewFlagSet("aptly-repo-edit", flag.ExitOnError), + } + + cmd.Flag.String("comment", "", "any text that would be used to described local repository") + cmd.Flag.String("distribution", "", "default distribution when publishing") + cmd.Flag.String("component", "", "default component when publishing") + + return cmd +}