Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Set local flags for each command #45

Merged
merged 1 commit into from
Sep 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ var RootCmd = &cobra.Command{
os.Exit(0)
}

initConfig()
cmd.Help()
},
}

Expand All @@ -41,8 +41,10 @@ func Execute(versionTag string) {
}

func init() {
RootCmd.Flags().BoolP("version", "v", false, "Print minima version")
// all sub-commands will have access to this flag
RootCmd.PersistentFlags().StringVarP(&cfgFile, "config", "c", "minima.yaml", "config file")
// local flags
RootCmd.Flags().BoolP("version", "v", false, "Print minima version")
}

// initConfig reads in config file and ENV variables if set.
Expand Down
9 changes: 6 additions & 3 deletions cmd/sync.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,8 @@ var (
# archs: [x86_64]
`,
Run: func(cmd *cobra.Command, args []string) {
initConfig()

var errorflag bool = false
syncers, err := syncersFromConfig(cfgString)
if err != nil {
Expand Down Expand Up @@ -157,7 +159,8 @@ func parseConfig(configString string) (Config, error) {

func init() {
RootCmd.AddCommand(syncCmd)
RootCmd.PersistentFlags().StringVarP(&thisRepo, "repository", "r", "", "flag that can specifies a single repo (example: SLES11-SP4-Updates)")
RootCmd.PersistentFlags().StringVarP(&archs, "arch", "a", "", "flag that specifies covered archs in the given repo")
RootCmd.PersistentFlags().BoolVarP(&syncLegacyPackages, "legacypackages", "l", false, "flag that triggers mirroring of i586 pkgs in x86_64 repos")
// local flags
syncCmd.Flags().StringVarP(&thisRepo, "repository", "r", "", "flag that can specifies a single repo (example: SLES11-SP4-Updates)")
syncCmd.Flags().StringVarP(&archs, "arch", "a", "", "flag that specifies covered archs in the given repo")
syncCmd.Flags().BoolVarP(&syncLegacyPackages, "legacypackages", "l", false, "flag that triggers mirroring of i586 pkgs in x86_64 repos")
}
14 changes: 8 additions & 6 deletions cmd/updates.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ import (

// mufnsCmd represents the mufns command
var (
update = &cobra.Command{
updateCmd = &cobra.Command{
Use: "updates",
Short: "searches all updates and syncs them to mirror",
Long: `A longer description that spans multiple lines and likely contains examples
Expand All @@ -46,6 +46,7 @@ Cobra is a CLI library for Go that empowers applications.
This application is a tool to generate the needed files
to quickly create a Cobra application.`,
Run: func(cmd *cobra.Command, args []string) {
initConfig()
muFindAndSync()
},
}
Expand All @@ -56,11 +57,12 @@ to quickly create a Cobra application.`,
)

func init() {
RootCmd.AddCommand(update)
RootCmd.PersistentFlags().BoolVarP(&spitYamls, "yaml", "y", false, "flag that would trigger generating minima_obs_<Date>.yaml configs")
RootCmd.PersistentFlags().BoolVarP(&justSearch, "search", "s", false, "flag that would trigger only looking for updates on OBS")
RootCmd.PersistentFlags().StringVarP(&thisMU, "maintupdate", "m", "", "flag that consumes the name of an MU, like 'SUSE:Maintenance:Incident:ReleaseRequest'")
RootCmd.PersistentFlags().BoolVarP(&cleanup, "cleanup", "k", false, "flag that triggers cleaning up the storage (from old MU channels)")
RootCmd.AddCommand(updateCmd)
// local flags
updateCmd.Flags().BoolVarP(&spitYamls, "yaml", "y", false, "flag that would trigger generating minima_obs_<Date>.yaml configs")
updateCmd.Flags().BoolVarP(&justSearch, "search", "s", false, "flag that would trigger only looking for updates on OBS")
updateCmd.Flags().StringVarP(&thisMU, "maintupdate", "m", "", "flag that consumes the name of an MU, like 'SUSE:Maintenance:Incident:ReleaseRequest'")
updateCmd.Flags().BoolVarP(&cleanup, "cleanup", "k", false, "flag that triggers cleaning up the storage (from old MU channels)")
}

func muFindAndSync() {
Expand Down