|
| 1 | +// Copyright © 2021 sealos. |
| 2 | +// |
| 3 | +// Licensed under the Apache License, Version 2.0 (the "License"); |
| 4 | +// you may not use this file except in compliance with the License. |
| 5 | +// You may obtain a copy of the License at |
| 6 | +// |
| 7 | +// http://www.apache.org/licenses/LICENSE-2.0 |
| 8 | +// |
| 9 | +// Unless required by applicable law or agreed to in writing, software |
| 10 | +// distributed under the License is distributed on an "AS IS" BASIS, |
| 11 | +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 12 | +// See the License for the specific language governing permissions and |
| 13 | +// limitations under the License. |
| 14 | + |
| 15 | +package cmd |
| 16 | + |
| 17 | +import ( |
| 18 | + "fmt" |
| 19 | + "github.com/labring/sreg/pkg/registry/commands" |
| 20 | + "github.com/labring/sreg/pkg/utils/logger" |
| 21 | + "os" |
| 22 | + |
| 23 | + "github.com/spf13/cobra" |
| 24 | +) |
| 25 | + |
| 26 | +var ( |
| 27 | + debug bool |
| 28 | +) |
| 29 | + |
| 30 | +// rootCmd represents the base command when called without any subcommands |
| 31 | +var rootCmd = &cobra.Command{ |
| 32 | + Use: "sreg", |
| 33 | + Short: "sealos registry related", |
| 34 | + // Uncomment the following line if your bare application |
| 35 | + // has an action associated with it: |
| 36 | + // Run: func(cmd *cobra.Command, args []string) { }, |
| 37 | +} |
| 38 | + |
| 39 | +// Execute adds all child commands to the root command and sets flags appropriately. |
| 40 | +// This is called by main.main(). It only needs to happen once to the rootCmd. |
| 41 | +func Execute() { |
| 42 | + if err := rootCmd.Execute(); err != nil { |
| 43 | + if rootCmd.SilenceErrors { |
| 44 | + fmt.Fprintln(os.Stderr, err) |
| 45 | + } |
| 46 | + os.Exit(1) |
| 47 | + } |
| 48 | +} |
| 49 | + |
| 50 | +func init() { |
| 51 | + cobra.OnInitialize(func() { |
| 52 | + logger.CfgConsoleLogger(debug, false) |
| 53 | + }) |
| 54 | + rootCmd.PersistentFlags().BoolVar(&debug, "debug", false, "enable debug logger") |
| 55 | + |
| 56 | +} |
| 57 | + |
| 58 | +func init() { |
| 59 | + examplePrefix := rootCmd.Name() |
| 60 | + rootCmd.AddCommand(commands.NewServeRegistryCommand()) |
| 61 | + rootCmd.AddCommand(commands.NewRegistryImageSaveCmd(examplePrefix)) |
| 62 | + rootCmd.AddCommand(commands.NewSyncRegistryCommand(examplePrefix)) |
| 63 | + rootCmd.AddCommand(commands.NewCopyRegistryCommand(examplePrefix)) |
| 64 | +} |
0 commit comments