From f648c9547cd4ff1b14f71f5ff3c19aa07e66f479 Mon Sep 17 00:00:00 2001 From: Andrey Smirnov Date: Thu, 3 Apr 2014 00:16:18 +0400 Subject: [PATCH] Support for switching to smira/commander with free placement of flags. #17 --- cmd/context.go | 25 +++++++++++++---------- cmd/db.go | 2 -- cmd/db_cleanup.go | 2 -- cmd/graph.go | 2 -- cmd/mirror.go | 11 +++++----- cmd/mirror_create.go | 6 +++--- cmd/mirror_drop.go | 2 +- cmd/mirror_list.go | 2 -- cmd/mirror_show.go | 2 +- cmd/mirror_update.go | 6 +++--- cmd/publish.go | 9 ++++---- cmd/publish_drop.go | 2 -- cmd/publish_list.go | 2 -- cmd/publish_repo.go | 2 +- cmd/publish_snapshot.go | 8 ++++---- cmd/repo.go | 2 -- cmd/repo_add.go | 2 +- cmd/repo_create.go | 6 +++--- cmd/repo_drop.go | 2 +- cmd/repo_edit.go | 12 +++++------ cmd/repo_list.go | 2 -- cmd/repo_move.go | 4 ++-- cmd/repo_remove.go | 2 +- cmd/repo_show.go | 2 +- cmd/serve.go | 2 +- cmd/snapshot.go | 2 -- cmd/snapshot_create.go | 2 -- cmd/snapshot_diff.go | 2 +- cmd/snapshot_drop.go | 2 +- cmd/snapshot_list.go | 2 -- cmd/snapshot_merge.go | 2 -- cmd/snapshot_pull.go | 6 +++--- cmd/snapshot_show.go | 2 +- cmd/snapshot_verify.go | 2 -- cmd/version.go | 2 -- main.go | 6 +++--- system/t03_help/MirrorCreateHelpTest_gold | 6 ++++++ system/t03_help/MirrorCreateTest_gold | 6 ++++++ system/t03_help/MirrorHelpTest_gold | 8 ++++++++ system/t03_help/MirrorTest_gold | 8 ++++++++ 40 files changed, 89 insertions(+), 88 deletions(-) diff --git a/cmd/context.go b/cmd/context.go index fe4bec66..3a544667 100644 --- a/cmd/context.go +++ b/cmd/context.go @@ -9,7 +9,7 @@ import ( "github.com/smira/aptly/files" "github.com/smira/aptly/http" "github.com/smira/aptly/utils" - "github.com/smira/commander" + "github.com/smira/flag" "os" "path/filepath" "runtime" @@ -28,6 +28,7 @@ var context struct { collectionFactory *debian.CollectionFactory dependencyOptions int architecturesList []string + flags *flag.FlagSet // Debug features fileCPUProfile *os.File fileMemProfile *os.File @@ -35,25 +36,27 @@ var context struct { } // InitContext initializes context with default settings -func InitContext(cmd *commander.Command) error { +func InitContext(flags *flag.FlagSet) error { var err error + context.flags = flags + context.dependencyOptions = 0 - if utils.Config.DepFollowSuggests || cmd.Flag.Lookup("dep-follow-suggests").Value.Get().(bool) { + if utils.Config.DepFollowSuggests || flags.Lookup("dep-follow-suggests").Value.Get().(bool) { context.dependencyOptions |= debian.DepFollowSuggests } - if utils.Config.DepFollowRecommends || cmd.Flag.Lookup("dep-follow-recommends").Value.Get().(bool) { + if utils.Config.DepFollowRecommends || flags.Lookup("dep-follow-recommends").Value.Get().(bool) { context.dependencyOptions |= debian.DepFollowRecommends } - if utils.Config.DepFollowAllVariants || cmd.Flag.Lookup("dep-follow-all-variants").Value.Get().(bool) { + if utils.Config.DepFollowAllVariants || flags.Lookup("dep-follow-all-variants").Value.Get().(bool) { context.dependencyOptions |= debian.DepFollowAllVariants } - if utils.Config.DepFollowSource || cmd.Flag.Lookup("dep-follow-source").Value.Get().(bool) { + if utils.Config.DepFollowSource || flags.Lookup("dep-follow-source").Value.Get().(bool) { context.dependencyOptions |= debian.DepFollowSource } context.architecturesList = utils.Config.Architectures - optionArchitectures := cmd.Flag.Lookup("architectures").Value.String() + optionArchitectures := flags.Lookup("architectures").Value.String() if optionArchitectures != "" { context.architecturesList = strings.Split(optionArchitectures, ",") } @@ -74,7 +77,7 @@ func InitContext(cmd *commander.Command) error { context.publishedStorage = files.NewPublishedStorage(utils.Config.RootDir) if aptly.EnableDebug { - cpuprofile := cmd.Flag.Lookup("cpuprofile").Value.String() + cpuprofile := flags.Lookup("cpuprofile").Value.String() if cpuprofile != "" { context.fileCPUProfile, err = os.Create(cpuprofile) if err != nil { @@ -83,7 +86,7 @@ func InitContext(cmd *commander.Command) error { pprof.StartCPUProfile(context.fileCPUProfile) } - memprofile := cmd.Flag.Lookup("memprofile").Value.String() + memprofile := flags.Lookup("memprofile").Value.String() if memprofile != "" { context.fileMemProfile, err = os.Create(memprofile) if err != nil { @@ -91,9 +94,9 @@ func InitContext(cmd *commander.Command) error { } } - memstats := cmd.Flag.Lookup("memstats").Value.String() + memstats := flags.Lookup("memstats").Value.String() if memstats != "" { - interval := cmd.Flag.Lookup("meminterval").Value.Get().(time.Duration) + interval := flags.Lookup("meminterval").Value.Get().(time.Duration) context.fileMemStats, err = os.Create(memstats) if err != nil { diff --git a/cmd/db.go b/cmd/db.go index 9505da3a..a6b51c73 100644 --- a/cmd/db.go +++ b/cmd/db.go @@ -2,7 +2,6 @@ package cmd import ( "github.com/smira/commander" - "github.com/smira/flag" ) func makeCmdDb() *commander.Command { @@ -12,6 +11,5 @@ func makeCmdDb() *commander.Command { Subcommands: []*commander.Command{ makeCmdDbCleanup(), }, - Flag: *flag.NewFlagSet("aptly-db", flag.ExitOnError), } } diff --git a/cmd/db_cleanup.go b/cmd/db_cleanup.go index 1e700672..85530f58 100644 --- a/cmd/db_cleanup.go +++ b/cmd/db_cleanup.go @@ -5,7 +5,6 @@ import ( "github.com/smira/aptly/debian" "github.com/smira/aptly/utils" "github.com/smira/commander" - "github.com/smira/flag" "sort" ) @@ -159,7 +158,6 @@ Example: $ aptly db cleanup `, - Flag: *flag.NewFlagSet("aptly-db-cleanup", flag.ExitOnError), } return cmd diff --git a/cmd/graph.go b/cmd/graph.go index c7767284..2fc6aea9 100644 --- a/cmd/graph.go +++ b/cmd/graph.go @@ -6,7 +6,6 @@ import ( "fmt" "github.com/smira/aptly/debian" "github.com/smira/commander" - "github.com/smira/flag" "io" "io/ioutil" "os" @@ -196,7 +195,6 @@ Example: $ aptly graph `, - Flag: *flag.NewFlagSet("aptly-graph", flag.ExitOnError), } return cmd diff --git a/cmd/mirror.go b/cmd/mirror.go index 0726d45d..cf3a102a 100644 --- a/cmd/mirror.go +++ b/cmd/mirror.go @@ -7,13 +7,15 @@ import ( "strings" ) -func getVerifier(cmd *commander.Command) (utils.Verifier, error) { - if utils.Config.GpgDisableVerify || cmd.Flag.Lookup("ignore-signatures").Value.Get().(bool) { +func getVerifier(flags *flag.FlagSet) (utils.Verifier, error) { + if utils.Config.GpgDisableVerify || flags.Lookup("ignore-signatures").Value.Get().(bool) { return nil, nil } + keyRings := flags.Lookup("keyring").Value.Get().([]string) + verifier := &utils.GpgVerifier{} - for _, keyRing := range keyRings.keyRings { + for _, keyRing := range keyRings { verifier.AddKeyring(keyRing) } @@ -42,8 +44,6 @@ func (k *keyRingsFlag) String() string { return strings.Join(k.keyRings, ",") } -var keyRings = keyRingsFlag{} - func makeCmdMirror() *commander.Command { return &commander.Command{ UsageLine: "mirror", @@ -55,6 +55,5 @@ func makeCmdMirror() *commander.Command { makeCmdMirrorDrop(), makeCmdMirrorUpdate(), }, - Flag: *flag.NewFlagSet("aptly-mirror", flag.ExitOnError), } } diff --git a/cmd/mirror_create.go b/cmd/mirror_create.go index effac6df..b6a37f55 100644 --- a/cmd/mirror_create.go +++ b/cmd/mirror_create.go @@ -16,7 +16,7 @@ func aptlyMirrorCreate(cmd *commander.Command, args []string) error { return err } - downloadSources := utils.Config.DownloadSourcePackages || cmd.Flag.Lookup("with-sources").Value.Get().(bool) + downloadSources := utils.Config.DownloadSourcePackages || context.flags.Lookup("with-sources").Value.Get().(bool) var ( mirrorName, archiveURL, distribution string @@ -38,7 +38,7 @@ func aptlyMirrorCreate(cmd *commander.Command, args []string) error { return fmt.Errorf("unable to create mirror: %s", err) } - verifier, err := getVerifier(cmd) + verifier, err := getVerifier(context.flags) if err != nil { return fmt.Errorf("unable to initialize GPG verifier: %s", err) } @@ -79,7 +79,7 @@ Example: cmd.Flag.Bool("ignore-signatures", false, "disable verification of Release file signatures") cmd.Flag.Bool("with-sources", false, "download source packages in addition to binary packages") - cmd.Flag.Var(&keyRings, "keyring", "gpg keyring to use when verifying Release file (could be specified multiple times)") + cmd.Flag.Var(&keyRingsFlag{}, "keyring", "gpg keyring to use when verifying Release file (could be specified multiple times)") return cmd } diff --git a/cmd/mirror_drop.go b/cmd/mirror_drop.go index 4b270a10..c94aee46 100644 --- a/cmd/mirror_drop.go +++ b/cmd/mirror_drop.go @@ -20,7 +20,7 @@ func aptlyMirrorDrop(cmd *commander.Command, args []string) error { return fmt.Errorf("unable to drop: %s", err) } - force := cmd.Flag.Lookup("force").Value.Get().(bool) + force := context.flags.Lookup("force").Value.Get().(bool) if !force { snapshots := context.collectionFactory.SnapshotCollection().ByRemoteRepoSource(repo) diff --git a/cmd/mirror_list.go b/cmd/mirror_list.go index 9c2d08e1..e4efc673 100644 --- a/cmd/mirror_list.go +++ b/cmd/mirror_list.go @@ -4,7 +4,6 @@ import ( "fmt" "github.com/smira/aptly/debian" "github.com/smira/commander" - "github.com/smira/flag" "sort" ) @@ -49,7 +48,6 @@ Example: $ aptly mirror list `, - Flag: *flag.NewFlagSet("aptly-mirror-list", flag.ExitOnError), } return cmd diff --git a/cmd/mirror_show.go b/cmd/mirror_show.go index 4a74c508..392edee3 100644 --- a/cmd/mirror_show.go +++ b/cmd/mirror_show.go @@ -49,7 +49,7 @@ func aptlyMirrorShow(cmd *commander.Command, args []string) error { fmt.Printf("%s: %s\n", k, repo.Meta[k]) } - withPackages := cmd.Flag.Lookup("with-packages").Value.Get().(bool) + withPackages := context.flags.Lookup("with-packages").Value.Get().(bool) if withPackages { if repo.LastDownloadDate.IsZero() { fmt.Printf("Unable to show package list, mirror hasn't been downloaded yet.\n") diff --git a/cmd/mirror_update.go b/cmd/mirror_update.go index 7b46da22..1796afd7 100644 --- a/cmd/mirror_update.go +++ b/cmd/mirror_update.go @@ -25,9 +25,9 @@ func aptlyMirrorUpdate(cmd *commander.Command, args []string) error { return fmt.Errorf("unable to update: %s", err) } - ignoreMismatch := cmd.Flag.Lookup("ignore-checksums").Value.Get().(bool) + ignoreMismatch := context.flags.Lookup("ignore-checksums").Value.Get().(bool) - verifier, err := getVerifier(cmd) + verifier, err := getVerifier(context.flags) if err != nil { return fmt.Errorf("unable to initialize GPG verifier: %s", err) } @@ -70,7 +70,7 @@ Example: cmd.Flag.Bool("ignore-checksums", false, "ignore checksum mismatches while downloading package files and metadata") cmd.Flag.Bool("ignore-signatures", false, "disable verification of Release file signatures") - cmd.Flag.Var(&keyRings, "keyring", "gpg keyring to use when verifying Release file (could be specified multiple times)") + cmd.Flag.Var(&keyRingsFlag{}, "keyring", "gpg keyring to use when verifying Release file (could be specified multiple times)") return cmd } diff --git a/cmd/publish.go b/cmd/publish.go index ef5b3f5b..bf9e4503 100644 --- a/cmd/publish.go +++ b/cmd/publish.go @@ -6,14 +6,14 @@ import ( "github.com/smira/flag" ) -func getSigner(cmd *commander.Command) (utils.Signer, error) { - if cmd.Flag.Lookup("skip-signing").Value.Get().(bool) || utils.Config.GpgDisableSign { +func getSigner(flags *flag.FlagSet) (utils.Signer, error) { + if flags.Lookup("skip-signing").Value.Get().(bool) || utils.Config.GpgDisableSign { return nil, nil } signer := &utils.GpgSigner{} - signer.SetKey(cmd.Flag.Lookup("gpg-key").Value.String()) - signer.SetKeyRing(cmd.Flag.Lookup("keyring").Value.String(), cmd.Flag.Lookup("secret-keyring").Value.String()) + signer.SetKey(flags.Lookup("gpg-key").Value.String()) + signer.SetKeyRing(flags.Lookup("keyring").Value.String(), flags.Lookup("secret-keyring").Value.String()) err := signer.Init() if err != nil { @@ -34,6 +34,5 @@ func makeCmdPublish() *commander.Command { makeCmdPublishList(), makeCmdPublishDrop(), }, - Flag: *flag.NewFlagSet("aptly-publish", flag.ExitOnError), } } diff --git a/cmd/publish_drop.go b/cmd/publish_drop.go index 61e9d29e..6aea6546 100644 --- a/cmd/publish_drop.go +++ b/cmd/publish_drop.go @@ -3,7 +3,6 @@ package cmd import ( "fmt" "github.com/smira/commander" - "github.com/smira/flag" ) func aptlyPublishDrop(cmd *commander.Command, args []string) error { @@ -43,7 +42,6 @@ Example: $ aptly publish drop wheezy `, - Flag: *flag.NewFlagSet("aptly-publish-drop", flag.ExitOnError), } return cmd diff --git a/cmd/publish_list.go b/cmd/publish_list.go index 852edcb5..1d188080 100644 --- a/cmd/publish_list.go +++ b/cmd/publish_list.go @@ -4,7 +4,6 @@ import ( "fmt" "github.com/smira/aptly/debian" "github.com/smira/commander" - "github.com/smira/flag" "sort" ) @@ -59,7 +58,6 @@ Example: $ aptly publish list `, - Flag: *flag.NewFlagSet("aptly-publish-list", flag.ExitOnError), } return cmd diff --git a/cmd/publish_repo.go b/cmd/publish_repo.go index ccd4e410..0e40aded 100644 --- a/cmd/publish_repo.go +++ b/cmd/publish_repo.go @@ -29,7 +29,7 @@ Example: cmd.Flag.String("distribution", "", "distribution name to publish") cmd.Flag.String("component", "", "component name to publish") cmd.Flag.String("gpg-key", "", "GPG key ID to use when signing the release") - cmd.Flag.String("keyring", "", "GPG keyring to use (instead of default)") + cmd.Flag.Var(&keyRingsFlag{}, "keyring", "GPG keyring to use (instead of default)") cmd.Flag.String("secret-keyring", "", "GPG secret keyring to use (instead of default)") cmd.Flag.Bool("skip-signing", false, "don't sign Release files with GPG") diff --git a/cmd/publish_snapshot.go b/cmd/publish_snapshot.go index 6773f86b..5b529543 100644 --- a/cmd/publish_snapshot.go +++ b/cmd/publish_snapshot.go @@ -60,8 +60,8 @@ func aptlyPublishSnapshotOrRepo(cmd *commander.Command, args []string) error { panic("unknown command") } - component := cmd.Flag.Lookup("component").Value.String() - distribution := cmd.Flag.Lookup("distribution").Value.String() + component := context.flags.Lookup("component").Value.String() + distribution := context.flags.Lookup("distribution").Value.String() published, err := debian.NewPublishedRepo(prefix, distribution, component, context.architecturesList, source, context.collectionFactory) if err != nil { @@ -74,7 +74,7 @@ func aptlyPublishSnapshotOrRepo(cmd *commander.Command, args []string) error { return fmt.Errorf("prefix/distribution already used by another published repo: %s", duplicate) } - signer, err := getSigner(cmd) + signer, err := getSigner(context.flags) if err != nil { return fmt.Errorf("unable to initialize GPG signer: %s", err) } @@ -128,7 +128,7 @@ Example: cmd.Flag.String("distribution", "", "distribution name to publish") cmd.Flag.String("component", "", "component name to publish") cmd.Flag.String("gpg-key", "", "GPG key ID to use when signing the release") - cmd.Flag.String("keyring", "", "GPG keyring to use (instead of default)") + cmd.Flag.Var(&keyRingsFlag{}, "keyring", "GPG keyring to use (instead of default)") cmd.Flag.String("secret-keyring", "", "GPG secret keyring to use (instead of default)") cmd.Flag.Bool("skip-signing", false, "don't sign Release files with GPG") diff --git a/cmd/repo.go b/cmd/repo.go index 47d9d455..1f3d64be 100644 --- a/cmd/repo.go +++ b/cmd/repo.go @@ -2,7 +2,6 @@ package cmd import ( "github.com/smira/commander" - "github.com/smira/flag" ) func makeCmdRepo() *commander.Command { @@ -21,6 +20,5 @@ func makeCmdRepo() *commander.Command { makeCmdRepoRemove(), makeCmdRepoShow(), }, - Flag: *flag.NewFlagSet("aptly-repo", flag.ExitOnError), } } diff --git a/cmd/repo_add.go b/cmd/repo_add.go index f2ddaf59..bda6e690 100644 --- a/cmd/repo_add.go +++ b/cmd/repo_add.go @@ -165,7 +165,7 @@ func aptlyRepoAdd(cmd *commander.Command, args []string) error { return fmt.Errorf("unable to save: %s", err) } - if cmd.Flag.Lookup("remove-files").Value.Get().(bool) { + if context.flags.Lookup("remove-files").Value.Get().(bool) { processedFiles = utils.StrSliceDeduplicate(processedFiles) for _, file := range processedFiles { diff --git a/cmd/repo_create.go b/cmd/repo_create.go index 4d4c768d..7c06010a 100644 --- a/cmd/repo_create.go +++ b/cmd/repo_create.go @@ -14,9 +14,9 @@ func aptlyRepoCreate(cmd *commander.Command, args []string) error { return err } - repo := debian.NewLocalRepo(args[0], cmd.Flag.Lookup("comment").Value.String()) - repo.DefaultDistribution = cmd.Flag.Lookup("distribution").Value.String() - repo.DefaultComponent = cmd.Flag.Lookup("component").Value.String() + repo := debian.NewLocalRepo(args[0], context.flags.Lookup("comment").Value.String()) + repo.DefaultDistribution = context.flags.Lookup("distribution").Value.String() + repo.DefaultComponent = context.flags.Lookup("component").Value.String() err = context.collectionFactory.LocalRepoCollection().Add(repo) if err != nil { diff --git a/cmd/repo_drop.go b/cmd/repo_drop.go index 3f68c0a2..fd5ca704 100644 --- a/cmd/repo_drop.go +++ b/cmd/repo_drop.go @@ -34,7 +34,7 @@ func aptlyRepoDrop(cmd *commander.Command, args []string) error { return fmt.Errorf("unable to drop: local repo is published") } - force := cmd.Flag.Lookup("force").Value.Get().(bool) + force := context.flags.Lookup("force").Value.Get().(bool) if !force { snapshots := context.collectionFactory.SnapshotCollection().ByLocalRepoSource(repo) diff --git a/cmd/repo_edit.go b/cmd/repo_edit.go index 28b6041d..d2caf587 100644 --- a/cmd/repo_edit.go +++ b/cmd/repo_edit.go @@ -23,16 +23,16 @@ func aptlyRepoEdit(cmd *commander.Command, args []string) error { return fmt.Errorf("unable to edit: %s", err) } - if cmd.Flag.Lookup("comment").Value.String() != "" { - repo.Comment = cmd.Flag.Lookup("comment").Value.String() + if context.flags.Lookup("comment").Value.String() != "" { + repo.Comment = context.flags.Lookup("comment").Value.String() } - if cmd.Flag.Lookup("distribution").Value.String() != "" { - repo.DefaultDistribution = cmd.Flag.Lookup("distribution").Value.String() + if context.flags.Lookup("distribution").Value.String() != "" { + repo.DefaultDistribution = context.flags.Lookup("distribution").Value.String() } - if cmd.Flag.Lookup("component").Value.String() != "" { - repo.DefaultComponent = cmd.Flag.Lookup("component").Value.String() + if context.flags.Lookup("component").Value.String() != "" { + repo.DefaultComponent = context.flags.Lookup("component").Value.String() } err = context.collectionFactory.LocalRepoCollection().Update(repo) diff --git a/cmd/repo_list.go b/cmd/repo_list.go index 427fa53d..ff3a2aa0 100644 --- a/cmd/repo_list.go +++ b/cmd/repo_list.go @@ -4,7 +4,6 @@ import ( "fmt" "github.com/smira/aptly/debian" "github.com/smira/commander" - "github.com/smira/flag" "sort" ) @@ -54,7 +53,6 @@ Example: $ aptly repo list `, - Flag: *flag.NewFlagSet("aptly-repo-list", flag.ExitOnError), } return cmd diff --git a/cmd/repo_move.go b/cmd/repo_move.go index 29b5a8c4..c35de5cc 100644 --- a/cmd/repo_move.go +++ b/cmd/repo_move.go @@ -86,7 +86,7 @@ func aptlyRepoMoveCopyImport(cmd *commander.Command, args []string) error { var architecturesList []string - withDeps := cmd.Flag.Lookup("with-deps").Value.Get().(bool) + withDeps := context.flags.Lookup("with-deps").Value.Get().(bool) if withDeps { dstList.PrepareIndex() @@ -136,7 +136,7 @@ func aptlyRepoMoveCopyImport(cmd *commander.Command, args []string) error { return fmt.Errorf("unable to %s: %s", command, err) } - if cmd.Flag.Lookup("dry-run").Value.Get().(bool) { + if context.flags.Lookup("dry-run").Value.Get().(bool) { context.progress.Printf("\nChanges not saved, as dry run has been requested.\n") } else { dstRepo.UpdateRefList(debian.NewPackageRefListFromPackageList(dstList)) diff --git a/cmd/repo_remove.go b/cmd/repo_remove.go index 3bf2c5d9..3306f2c4 100644 --- a/cmd/repo_remove.go +++ b/cmd/repo_remove.go @@ -45,7 +45,7 @@ func aptlyRepoRemove(cmd *commander.Command, args []string) error { return nil }) - if cmd.Flag.Lookup("dry-run").Value.Get().(bool) { + if context.flags.Lookup("dry-run").Value.Get().(bool) { context.progress.Printf("\nChanges not saved, as dry run has been requested.\n") } else { repo.UpdateRefList(debian.NewPackageRefListFromPackageList(list)) diff --git a/cmd/repo_show.go b/cmd/repo_show.go index 1115c8d6..e0134b49 100644 --- a/cmd/repo_show.go +++ b/cmd/repo_show.go @@ -31,7 +31,7 @@ func aptlyRepoShow(cmd *commander.Command, args []string) error { fmt.Printf("Default Component: %s\n", repo.DefaultComponent) fmt.Printf("Number of packages: %d\n", repo.NumPackages()) - withPackages := cmd.Flag.Lookup("with-packages").Value.Get().(bool) + withPackages := context.flags.Lookup("with-packages").Value.Get().(bool) if withPackages { ListPackagesRefList(repo.RefList()) } diff --git a/cmd/serve.go b/cmd/serve.go index 8f687880..e4622669 100644 --- a/cmd/serve.go +++ b/cmd/serve.go @@ -20,7 +20,7 @@ func aptlyServe(cmd *commander.Command, args []string) error { return nil } - listen := cmd.Flag.Lookup("listen").Value.String() + listen := context.flags.Lookup("listen").Value.String() listenHost, listenPort, err := net.SplitHostPort(listen) diff --git a/cmd/snapshot.go b/cmd/snapshot.go index 987d11a1..1581b250 100644 --- a/cmd/snapshot.go +++ b/cmd/snapshot.go @@ -2,7 +2,6 @@ package cmd import ( "github.com/smira/commander" - "github.com/smira/flag" ) func makeCmdSnapshot() *commander.Command { @@ -19,6 +18,5 @@ func makeCmdSnapshot() *commander.Command { makeCmdSnapshotMerge(), makeCmdSnapshotDrop(), }, - Flag: *flag.NewFlagSet("aptly-snapshot", flag.ExitOnError), } } diff --git a/cmd/snapshot_create.go b/cmd/snapshot_create.go index 7cb1cf3c..cb09f88d 100644 --- a/cmd/snapshot_create.go +++ b/cmd/snapshot_create.go @@ -4,7 +4,6 @@ import ( "fmt" "github.com/smira/aptly/debian" "github.com/smira/commander" - "github.com/smira/flag" ) func aptlySnapshotCreate(cmd *commander.Command, args []string) error { @@ -97,7 +96,6 @@ Example: $ aptly snapshot create wheezy-main-today from mirror wheezy-main `, - Flag: *flag.NewFlagSet("aptly-snapshot-create", flag.ExitOnError), } return cmd diff --git a/cmd/snapshot_diff.go b/cmd/snapshot_diff.go index 9052645b..e18a5bd6 100644 --- a/cmd/snapshot_diff.go +++ b/cmd/snapshot_diff.go @@ -13,7 +13,7 @@ func aptlySnapshotDiff(cmd *commander.Command, args []string) error { return err } - onlyMatching := cmd.Flag.Lookup("only-matching").Value.Get().(bool) + onlyMatching := context.flags.Lookup("only-matching").Value.Get().(bool) // Load snapshot snapshotA, err := context.collectionFactory.SnapshotCollection().ByName(args[0]) diff --git a/cmd/snapshot_drop.go b/cmd/snapshot_drop.go index f080b365..d12b2f24 100644 --- a/cmd/snapshot_drop.go +++ b/cmd/snapshot_drop.go @@ -35,7 +35,7 @@ func aptlySnapshotDrop(cmd *commander.Command, args []string) error { return fmt.Errorf("unable to drop: snapshot is published") } - force := cmd.Flag.Lookup("force").Value.Get().(bool) + force := context.flags.Lookup("force").Value.Get().(bool) if !force { snapshots := context.collectionFactory.SnapshotCollection().BySnapshotSource(snapshot) if len(snapshots) > 0 { diff --git a/cmd/snapshot_list.go b/cmd/snapshot_list.go index 573d0296..3f20da88 100644 --- a/cmd/snapshot_list.go +++ b/cmd/snapshot_list.go @@ -4,7 +4,6 @@ import ( "fmt" "github.com/smira/aptly/debian" "github.com/smira/commander" - "github.com/smira/flag" "sort" ) @@ -52,7 +51,6 @@ Example: $ aptly snapshot list `, - Flag: *flag.NewFlagSet("aptly-snapshot-list", flag.ExitOnError), } return cmd diff --git a/cmd/snapshot_merge.go b/cmd/snapshot_merge.go index da38fb6d..86226252 100644 --- a/cmd/snapshot_merge.go +++ b/cmd/snapshot_merge.go @@ -4,7 +4,6 @@ import ( "fmt" "github.com/smira/aptly/debian" "github.com/smira/commander" - "github.com/smira/flag" "strings" ) @@ -70,7 +69,6 @@ Example: $ aptly snapshot merge wheezy-w-backports wheezy-main wheezy-backports `, - Flag: *flag.NewFlagSet("aptly-snapshot-merge", flag.ExitOnError), } return cmd diff --git a/cmd/snapshot_pull.go b/cmd/snapshot_pull.go index a107c079..3be4bc78 100644 --- a/cmd/snapshot_pull.go +++ b/cmd/snapshot_pull.go @@ -16,8 +16,8 @@ func aptlySnapshotPull(cmd *commander.Command, args []string) error { return err } - noDeps := cmd.Flag.Lookup("no-deps").Value.Get().(bool) - noRemove := cmd.Flag.Lookup("no-remove").Value.Get().(bool) + noDeps := context.flags.Lookup("no-deps").Value.Get().(bool) + noRemove := context.flags.Lookup("no-remove").Value.Get().(bool) // Load snapshot snapshot, err := context.collectionFactory.SnapshotCollection().ByName(args[0]) @@ -147,7 +147,7 @@ func aptlySnapshotPull(cmd *commander.Command, args []string) error { } } - if cmd.Flag.Lookup("dry-run").Value.Get().(bool) { + if context.flags.Lookup("dry-run").Value.Get().(bool) { context.progress.Printf("\nNot creating snapshot, as dry run was requested.\n") } else { // Create snapshot diff --git a/cmd/snapshot_show.go b/cmd/snapshot_show.go index f7122fec..fb9408cb 100644 --- a/cmd/snapshot_show.go +++ b/cmd/snapshot_show.go @@ -30,7 +30,7 @@ func aptlySnapshotShow(cmd *commander.Command, args []string) error { fmt.Printf("Description: %s\n", snapshot.Description) fmt.Printf("Number of packages: %d\n", snapshot.NumPackages()) - withPackages := cmd.Flag.Lookup("with-packages").Value.Get().(bool) + withPackages := context.flags.Lookup("with-packages").Value.Get().(bool) if withPackages { ListPackagesRefList(snapshot.RefList()) } diff --git a/cmd/snapshot_verify.go b/cmd/snapshot_verify.go index 13a3bd7a..523aa4bd 100644 --- a/cmd/snapshot_verify.go +++ b/cmd/snapshot_verify.go @@ -4,7 +4,6 @@ import ( "fmt" "github.com/smira/aptly/debian" "github.com/smira/commander" - "github.com/smira/flag" "sort" ) @@ -110,7 +109,6 @@ Example: $ aptly snapshot verify wheezy-main wheezy-contrib wheezy-non-free `, - Flag: *flag.NewFlagSet("aptly-snapshot-verify", flag.ExitOnError), } return cmd diff --git a/cmd/version.go b/cmd/version.go index 03ec76f5..7d1d5814 100644 --- a/cmd/version.go +++ b/cmd/version.go @@ -4,7 +4,6 @@ import ( "fmt" "github.com/smira/aptly/aptly" "github.com/smira/commander" - "github.com/smira/flag" ) func aptlyVersion(cmd *commander.Command, args []string) error { @@ -23,6 +22,5 @@ Shows aptly version. ex: $ aptly version `, - Flag: *flag.NewFlagSet("aptly-version", flag.ExitOnError), } } diff --git a/main.go b/main.go index ae4c1b96..71b0e857 100644 --- a/main.go +++ b/main.go @@ -67,7 +67,7 @@ func main() { command := cmd.RootCommand() - err := command.Flag.Parse(os.Args[1:]) + flags, args, err := command.ParseFlags(os.Args[1:]) if err != nil { fatal(err) return @@ -82,14 +82,14 @@ func main() { return } - err = cmd.InitContext(command) + err = cmd.InitContext(flags) if err != nil { fatal(err) return } defer cmd.ShutdownContext() - err = command.Dispatch(command.Flag.Args()) + err = command.Dispatch(args) if err != nil { fatal(err) return diff --git a/system/t03_help/MirrorCreateHelpTest_gold b/system/t03_help/MirrorCreateHelpTest_gold index d24cfdeb..88c1a348 100644 --- a/system/t03_help/MirrorCreateHelpTest_gold +++ b/system/t03_help/MirrorCreateHelpTest_gold @@ -12,6 +12,12 @@ Example: $ aptly mirror create wheezy-main http://mirror.yandex.ru/debian/ wheezy main Options: + -architectures="": list of architectures to consider during (comma-separated), default to all available + -config="": location of configuration file (default locations are /etc/aptly.conf, ~/.aptly.conf) + -dep-follow-all-variants=false: when processing dependencies, follow a & b if depdency is 'a|b' + -dep-follow-recommends=false: when processing dependencies, follow Recommends + -dep-follow-source=false: when processing dependencies, follow from binary to Source packages + -dep-follow-suggests=false: when processing dependencies, follow Suggests -ignore-signatures=false: disable verification of Release file signatures -keyring=: gpg keyring to use when verifying Release file (could be specified multiple times) -with-sources=false: download source packages in addition to binary packages diff --git a/system/t03_help/MirrorCreateTest_gold b/system/t03_help/MirrorCreateTest_gold index 36c428ec..67815d57 100644 --- a/system/t03_help/MirrorCreateTest_gold +++ b/system/t03_help/MirrorCreateTest_gold @@ -4,6 +4,12 @@ aptly mirror create - create new mirror Options: + -architectures="": list of architectures to consider during (comma-separated), default to all available + -config="": location of configuration file (default locations are /etc/aptly.conf, ~/.aptly.conf) + -dep-follow-all-variants=false: when processing dependencies, follow a & b if depdency is 'a|b' + -dep-follow-recommends=false: when processing dependencies, follow Recommends + -dep-follow-source=false: when processing dependencies, follow from binary to Source packages + -dep-follow-suggests=false: when processing dependencies, follow Suggests -ignore-signatures=false: disable verification of Release file signatures -keyring=: gpg keyring to use when verifying Release file (could be specified multiple times) -with-sources=false: download source packages in addition to binary packages diff --git a/system/t03_help/MirrorHelpTest_gold b/system/t03_help/MirrorHelpTest_gold index b04394c3..fa07508c 100644 --- a/system/t03_help/MirrorHelpTest_gold +++ b/system/t03_help/MirrorHelpTest_gold @@ -10,3 +10,11 @@ Commands: Use "mirror help " for more information about a command. + +Options: + -architectures="": list of architectures to consider during (comma-separated), default to all available + -config="": location of configuration file (default locations are /etc/aptly.conf, ~/.aptly.conf) + -dep-follow-all-variants=false: when processing dependencies, follow a & b if depdency is 'a|b' + -dep-follow-recommends=false: when processing dependencies, follow Recommends + -dep-follow-source=false: when processing dependencies, follow from binary to Source packages + -dep-follow-suggests=false: when processing dependencies, follow Suggests diff --git a/system/t03_help/MirrorTest_gold b/system/t03_help/MirrorTest_gold index b04394c3..fa07508c 100644 --- a/system/t03_help/MirrorTest_gold +++ b/system/t03_help/MirrorTest_gold @@ -10,3 +10,11 @@ Commands: Use "mirror help " for more information about a command. + +Options: + -architectures="": list of architectures to consider during (comma-separated), default to all available + -config="": location of configuration file (default locations are /etc/aptly.conf, ~/.aptly.conf) + -dep-follow-all-variants=false: when processing dependencies, follow a & b if depdency is 'a|b' + -dep-follow-recommends=false: when processing dependencies, follow Recommends + -dep-follow-source=false: when processing dependencies, follow from binary to Source packages + -dep-follow-suggests=false: when processing dependencies, follow Suggests