Exemple #1
0
func NewMigration(cmd *cobra.Command, args []string) {
	if len(args) != 1 {
		cmd.Help()
		os.Exit(1)
	}

	name := args[0]

	migrationsPath := cliOptions.migrationsPath
	migrations, err := migrate.FindMigrations(migrationsPath)
	if err != nil {
		fmt.Fprintf(os.Stderr, "Error loading migrations:\n  %v\n", err)
		os.Exit(1)
	}

	newMigrationName := fmt.Sprintf("%03d_%s.sql", len(migrations)+1, name)

	// Write new migration
	mPath := filepath.Join(migrationsPath, newMigrationName)
	mFile, err := os.OpenFile(mPath, os.O_CREATE|os.O_EXCL|os.O_WRONLY, os.ModePerm)
	if err != nil {
		fmt.Fprintln(os.Stderr, err)
		os.Exit(1)
	}
	defer mFile.Close()

	_, err = mFile.WriteString(newMigrationText)
	if err != nil {
		fmt.Fprintln(os.Stderr, err)
		os.Exit(1)
	}

}
Exemple #2
0
// Complete verifies command line arguments and loads data from the command environment
func (o *RsyncOptions) Complete(f *clientcmd.Factory, cmd *cobra.Command, args []string) error {
	switch n := len(args); {
	case n == 0:
		cmd.Help()
		fallthrough
	case n < 2:
		return kcmdutil.UsageError(cmd, "SOURCE_DIR and POD:DESTINATION_DIR are required arguments")
	case n > 2:
		return kcmdutil.UsageError(cmd, "only SOURCE_DIR and POD:DESTINATION_DIR should be specified as arguments")
	}

	// Set main command arguments
	var err error
	o.Source, err = parsePathSpec(args[0])
	if err != nil {
		return err
	}
	o.Destination, err = parsePathSpec(args[1])
	if err != nil {
		return err
	}

	namespace, _, err := f.DefaultNamespace()
	if err != nil {
		return err
	}
	o.Namespace = namespace

	o.Strategy, err = o.determineStrategy(f, cmd, o.StrategyName)
	if err != nil {
		return err
	}

	return nil
}
Exemple #3
0
// runStatus is the code that implements the status command.
func runStatus(cmd *cobra.Command, args []string) {
	cmd.Printf("Status User : Pid[%s] Email[%s] Active[%v]\n", status.pid, status.email, status.active)

	if status.pid == "" && status.email == "" {
		cmd.Help()
		return
	}

	db := db.NewMGO()
	defer db.CloseMGO()

	var publicID string
	if status.pid != "" {
		publicID = status.pid
	} else {
		u, err := auth.GetUserByEmail("", db, status.email, false)
		if err != nil {
			cmd.Println("Status User : "******"", db, publicID, st); err != nil {
		cmd.Println("Status User : "******"Status User : Updated")
}
Exemple #4
0
// versionInfo displays the build and versioning information.
func versionInfo(cmd *cli.Command, args []string) {
	if version {
		fmt.Println(common.BuildInfo())
		os.Exit(0)
	}
	cmd.Help()
}
Exemple #5
0
// runCreate is the code that implements the create command.
func runCreate(cmd *cobra.Command, args []string) {
	cmd.Printf("Creating User : Name[%s] Email[%s] Pass[%s]\n", create.name, create.email, create.pass)

	if create.name == "" && create.email == "" && create.pass == "" {
		cmd.Help()
		return
	}

	u, err := auth.NewUser(auth.NUser{
		Status:   auth.StatusActive,
		FullName: create.name,
		Email:    create.email,
		Password: create.pass,
	})
	if err != nil {
		cmd.Println("Creating User : "******"", conn, u); err != nil {
		cmd.Println("Creating User : "******"", conn, u, 24*365*time.Hour)
	if err != nil {
		cmd.Println("Creating User : "******"\nToken: %s\n\n", webTok)
}
Exemple #6
0
// Where all the work happens.
func performCommand(cmd *cobra.Command, args []string) error {
	if displayVersion {
		fmt.Printf("%s %s\n", appName, version)
		return nil
	}

	if listProviders {
		fmt.Printf(providers.DisplayProviders())
		return nil
	}

	query := strings.Join(args, " ")

	if query != "" {
		err := providers.Search(binary, provider, query, verbose)
		if err != nil {
			return err
		}
	} else {
		// Don't return an error, help screen is more appropriate.
		cmd.Help()
	}

	return nil
}
Exemple #7
0
func runDeleteContext(out io.Writer, configAccess clientcmd.ConfigAccess, cmd *cobra.Command) error {
	config, err := configAccess.GetStartingConfig()
	if err != nil {
		return err
	}

	args := cmd.Flags().Args()
	if len(args) != 1 {
		cmd.Help()
		return nil
	}

	configFile := configAccess.GetDefaultFilename()
	if configAccess.IsExplicitFile() {
		configFile = configAccess.GetExplicitFile()
	}

	name := args[0]
	_, ok := config.Contexts[name]
	if !ok {
		return fmt.Errorf("cannot delete context %s, not in %s", name, configFile)
	}

	delete(config.Contexts, name)

	if err := clientcmd.ModifyConfig(configAccess, *config, true); err != nil {
		return err
	}

	fmt.Fprintf(out, "deleted context %s from %s", name, configFile)

	return nil
}
Exemple #8
0
func (o *NewProjectOptions) complete(cmd *cobra.Command, f *clientcmd.Factory) error {
	args := cmd.Flags().Args()
	if len(args) != 1 {
		cmd.Help()
		return errors.New("must have exactly one argument")
	}

	o.ProjectName = args[0]

	if !o.SkipConfigWrite {
		o.ProjectOptions = &ProjectOptions{}
		o.ProjectOptions.PathOptions = cliconfig.NewPathOptions(cmd)
		if err := o.ProjectOptions.Complete(f, []string{""}, o.Out); err != nil {
			return err
		}
	} else {
		clientConfig, err := f.OpenShiftClientConfig.ClientConfig()
		if err != nil {
			return err
		}
		o.Server = clientConfig.Host
	}

	return nil
}
Exemple #9
0
func CommandSave(cmd *cobra.Command, args []string) {
	mustLoadConfig(cmd)
	now := time.Now()

	// find the directory
	dir := ""
	switch len(args) {
	case 0:
		dir = "."
	case 1:
		dir = args[0]
	default:
		cmd.Help()
		return
	}

	problem, _, commit, _ := gather(now, dir)
	commit.Action = ""
	commit.Note = "saving from grind tool"
	unsigned := &CommitBundle{Commit: commit}

	// send the commit to the server
	signed := new(CommitBundle)
	mustPostObject("/commit_bundles/unsigned", nil, unsigned, signed)
	log.Printf("problem %s step %d saved", problem.Unique, commit.Step)
}
Exemple #10
0
func login(cmd *cobra.Command, args []string) {

	if len(args) != 2 {
		cmd.Help()
		os.Exit(1)
	}

	con, err := grpc.Dial(authAddr, grpc.WithInsecure())
	if err != nil {
		log.Error(err)
		fmt.Println("Cannot connect to authentication unit")
		os.Exit(1)
	}

	defer con.Close()

	c := pb.NewAuthClient(con)

	in := &pb.AuthRequest{}
	in.Username = args[0]
	in.Password = args[1]

	ctx := context.Background()

	res, err := c.Authenticate(ctx, in)
	if err != nil {
		if grpc.Code(err) == codes.Unauthenticated {
			fmt.Println("Invalid username or password")
			os.Exit(1)
		}
		fmt.Println("Cannot connect to authentication unit")
		os.Exit(1)
	}

	// Save token into $HOME/.clawiobench/credentials
	u, err := user.Current()
	if err != nil {
		log.Error(err)
		fmt.Println("Cannot access your home directory")
		os.Exit(1)
	}

	err = os.MkdirAll(path.Join(u.HomeDir, ".clawiobench"), 0755)
	if err != nil {
		log.Error(err)
		fmt.Println("Cannot create $HOME/.clawiobench configuration directory")
		os.Exit(1)
	}

	err = ioutil.WriteFile(path.Join(u.HomeDir, ".clawiobench", "credentials"), []byte(res.Token), 0644)
	if err != nil {
		log.Error(err)
		fmt.Println("Cannot save credentials into $HOME/.clawiobench/credentials")
		os.Exit(1)
	}

	fmt.Println("You are logged in as " + in.Username)
	os.Exit(0)
}
Exemple #11
0
func MakeChain(cmd *cobra.Command, args []string) {
	argsMin := 1
	if len(args) < argsMin {
		cmd.Help()
		IfExit(fmt.Errorf("\n**Note** you sent our marmots the wrong number of arguments.\nPlease send the marmots at least %d argument(s).", argsMin))
	}
	do.Name = args[0]
	IfExit(maker.MakeChain(do))
}
Exemple #12
0
func (c *CLI) preRun(cmd *cobra.Command, args []string) {

	if c.cfgFile != "" && gotil.FileExists(c.cfgFile) {
		if err := c.r.Config.ReadConfigFile(c.cfgFile); err != nil {
			panic(err)
		}
		cmd.Flags().Parse(os.Args[1:])
	}

	c.updateLogLevel()

	c.r.Config = c.r.Config.Scope("rexray.modules.default-docker")

	if isHelpFlag(cmd) {
		cmd.Help()
		panic(&helpFlagPanic{})
	}

	if permErr := c.checkCmdPermRequirements(cmd); permErr != nil {
		if term.IsTerminal() {
			printColorizedError(permErr)
		} else {
			printNonColorizedError(permErr)
		}

		fmt.Println()
		cmd.Help()
		panic(&printedErrorPanic{})
	}

	if c.isInitDriverManagersCmd(cmd) {
		if err := c.r.InitDrivers(); err != nil {

			if term.IsTerminal() {
				printColorizedError(err)
			} else {
				printNonColorizedError(err)
			}
			fmt.Println()

			helpCmd := cmd
			if cmd == c.volumeCmd {
				helpCmd = c.volumeGetCmd
			} else if cmd == c.snapshotCmd {
				helpCmd = c.snapshotGetCmd
			} else if cmd == c.deviceCmd {
				helpCmd = c.deviceGetCmd
			} else if cmd == c.adapterCmd {
				helpCmd = c.adapterGetTypesCmd
			}
			helpCmd.Help()

			panic(&printedErrorPanic{})
		}
	}
}
func (o *useContextOptions) complete(cmd *cobra.Command) bool {
	endingArgs := cmd.Flags().Args()
	if len(endingArgs) != 1 {
		cmd.Help()
		return false
	}

	o.contextName = endingArgs[0]
	return true
}
Exemple #14
0
func Assigned(cmd *cobra.Command, args []string) {
	if len(args) == 1 {
		cmd.Help()
	} else if len(args) == 0 {
		fip := AssignedFIP(cmd)
		fmt.Println(fip)
	} else {
		os.Exit(1)
	}
}
Exemple #15
0
func (o *createClusterOptions) complete(cmd *cobra.Command) bool {
	args := cmd.Flags().Args()
	if len(args) != 1 {
		cmd.Help()
		return false
	}

	o.name = args[0]
	return true
}
Exemple #16
0
// Where all the work happens.
func performCommand(cmd *cobra.Command, args []string) error {
	if config.DisplayVersion {
		fmt.Printf("%s %s\n", appName, version)
		return nil
	}

	providers.SetBlacklist(config.Blacklist)
	providers.SetWhitelist(config.Whitelist)

	if config.ListProviders {
		fmt.Printf(providers.DisplayProviders())
		return nil
	}

	if config.ServerMode {
		err := server.Run(config.Port, config.Cert, config.Key, config.Provider)
		if err != nil {
			return err
		}

		return nil
	}

	query := strings.Join(args, " ")

	st, err := os.Stdin.Stat()
	if err != nil {
		// os.Stdin.Stat() can be unavailable on Windows.
		if runtime.GOOS != "windows" {
			return fmt.Errorf("Failed to stat Stdin: %s", err)
		}
	} else {
		if st.Mode()&os.ModeNamedPipe != 0 {
			bytes, err := ioutil.ReadAll(os.Stdin)
			if err != nil {
				return fmt.Errorf("Failed to read from Stdin: %s", err)
			}

			query = strings.TrimSpace(fmt.Sprintf("%s %s", query, bytes))
		}
	}

	if query != "" {
		err := providers.Search(config.Binary, config.Provider, query, config.Verbose)
		if err != nil {
			return err
		}
	} else {
		// Don't return an error, help screen is more appropriate.
		cmd.Help()
	}

	return nil
}
Exemple #17
0
func preRun(cmd *cobra.Command, args []string) {

	if cfgFile != "" && util.FileExists(cfgFile) {
		if err := c.ReadConfigFile(cfgFile); err != nil {
			panic(err)
		}
		cmd.Flags().Parse(os.Args[1:])
	}

	updateLogLevel()

	if isHelpFlag(cmd) {
		cmd.Help()
		panic(&HelpFlagPanic{})
	}

	if permErr := checkCmdPermRequirements(cmd); permErr != nil {
		if term.IsTerminal() {
			printColorizedError(permErr)
		} else {
			printNonColorizedError(permErr)
		}

		fmt.Println()
		cmd.Help()
		panic(&PrintedErrorPanic{})
	}

	if isInitDriverManagersCmd(cmd) {
		if initDmErr := initDriverManagers(); initDmErr != nil {

			if term.IsTerminal() {
				printColorizedError(initDmErr)
			} else {
				printNonColorizedError(initDmErr)
			}
			fmt.Println()

			helpCmd := cmd
			if cmd == volumeCmd {
				helpCmd = volumeGetCmd
			} else if cmd == snapshotCmd {
				helpCmd = snapshotGetCmd
			} else if cmd == deviceCmd {
				helpCmd = deviceGetCmd
			} else if cmd == adapterCmd {
				helpCmd = adapterGetTypesCmd
			}
			helpCmd.Help()

			panic(&PrintedErrorPanic{})
		}
	}
}
func (o *DeleteApplicationOptions) complete(cmd *cobra.Command, f *clientcmd.Factory) error {
	args := cmd.Flags().Args()
	if len(args) != 1 {
		cmd.Help()
		return errors.New("must have exactly one argument")
	}

	o.Name = args[0]

	return nil
}
func (o *setOptions) complete(cmd *cobra.Command) bool {
	endingArgs := cmd.Flags().Args()
	if len(endingArgs) != 2 {
		cmd.Help()
		return false
	}

	o.propertyValue = endingArgs[1]
	o.propertyName = endingArgs[0]
	return true
}
Exemple #20
0
// Show information about a Floating IP.
func Show(cmd *cobra.Command, args []string) {
	if len(args) == 1 {
		floatingIP := doShow(args[0])
		printShow(floatingIP)
	} else if len(args) == 0 {
		fip := AssignedFIP(cmd)
		floatingIP := doShow(fip)
		printShow(floatingIP)
	} else {
		cmd.Help()
	}
}
Exemple #21
0
// WhoAmI returns a Droplet's ID via the Metadata service if run on one.
func WhoAmI(cmd *cobra.Command) int {
	client := metadata.NewClient(metadata.WithBaseURL(MetadataBase))

	id, err := client.DropletID()
	if err != nil {
		fmt.Println("Error: ", err)
		cmd.Help()
		os.Exit(1)
	}

	return id
}
func (o *UnbindBackingServiceInstanceOptions) complete(cmd *cobra.Command, f *clientcmd.Factory) error {
	args := cmd.Flags().Args()
	if len(args) < 2 {
		cmd.Help()
		return errors.New("must have at least 2 arguments")
	}

	o.Name = args[0]
	o.DeploymentConfigName = args[1]

	return nil
}
Exemple #23
0
func rootRun(cmd *cobra.Command, args []string) {
	fmt.Println(viper.GetString("appname"))
	fmt.Println(viper.GetString("server.ip"))
	fmt.Println(viper.GetString("server.http_port"))
	fmt.Println(viper.GetString("server.https_port"))
	fmt.Println(viper.GetString("server.cert"))
	fmt.Println(viper.GetString("server.key"))
	fmt.Println(viper.GetString("database.mongodb_uri"))
	err := cmd.Help()
	if err != nil {
		Logger.Println(err)
	}
}
Exemple #24
0
func AssignedFIP(cmd *cobra.Command) string {
	meta := metadata.NewClient(metadata.WithBaseURL(MetadataBase))
	all, err := meta.Metadata()

	if err != nil {
		fmt.Println("Error: ", err)
		cmd.Help()
		os.Exit(1)
	}

	fip := all.FloatingIP.IPv4.IPAddress

	return fip
}
Exemple #25
0
func nmUsage(cmd *cobra.Command, err error) {
	if err != nil {
		sErr := err.(*util.NewtError)
		log.Debugf("%s", sErr.StackTrace)
		fmt.Fprintf(os.Stderr, "Error: %s\n", sErr.Text)
	}

	if cmd != nil {
		fmt.Printf("\n")
		fmt.Printf("%s - ", cmd.Name())
		cmd.Help()
	}
	os.Exit(1)
}
Exemple #26
0
// Destroy a Floating IP.
func Destroy(cmd *cobra.Command, args []string) {
	client := GetClient(Token)

	if len(args) == 1 {
		_, err := client.FloatingIPs.Delete(args[0])

		if err != nil {
			fmt.Println("Error: ", err)
			os.Exit(1)
		}

		fmt.Println("Successfully destroyed Floating IP:", args[0])
	} else {
		cmd.Help()
	}
}
Exemple #27
0
func Init(cmd *cobra.Command, args []string) {
	var directory string
	switch len(args) {
	case 0:
		directory = "."
	case 1:
		directory = args[0]
		err := os.Mkdir(directory, os.ModePerm)
		if err != nil {
			fmt.Fprintln(os.Stderr, err)
			os.Exit(1)
		}
	default:
		cmd.Help()
		os.Exit(1)
	}

	// Write default conf file
	confPath := filepath.Join(directory, "tern.conf")
	confFile, err := os.OpenFile(confPath, os.O_CREATE|os.O_EXCL|os.O_WRONLY, os.ModePerm)
	if err != nil {
		fmt.Fprintln(os.Stderr, err)
		os.Exit(1)
	}
	defer confFile.Close()

	_, err = confFile.WriteString(defaultConf)
	if err != nil {
		fmt.Fprintln(os.Stderr, err)
		os.Exit(1)
	}

	// Write sample migration
	smPath := filepath.Join(directory, "001_create_people.sql.example")
	smFile, err := os.OpenFile(smPath, os.O_CREATE|os.O_EXCL|os.O_WRONLY, os.ModePerm)
	if err != nil {
		fmt.Fprintln(os.Stderr, err)
		os.Exit(1)
	}
	defer smFile.Close()

	_, err = smFile.WriteString(sampleMigration)
	if err != nil {
		fmt.Fprintln(os.Stderr, err)
		os.Exit(1)
	}
}
Exemple #28
0
func preRun(cmd *cobra.Command, args []string) {
	updateLogLevel()

	if isHelpFlag(cmd) {
		cmd.Help()
		panic(&HelpFlagPanic{})
	}

	if permErr := checkCmdPermRequirements(cmd); permErr != nil {
		if terminal.IsTerminal() {
			printColorizedError(permErr)
		} else {
			printNonColorizedError(permErr)
		}

		fmt.Println()
		cmd.Help()
		panic(&PrintedErrorPanic{})
	}

	if isInitDriverManagersCmd(cmd) {
		if initDmErr := initDriverManagers(); initDmErr != nil {

			if terminal.IsTerminal() {
				printColorizedError(initDmErr)
			} else {
				printNonColorizedError(initDmErr)
			}
			fmt.Println()

			helpCmd := cmd
			if cmd == volumeCmd {
				helpCmd = volumeGetCmd
			} else if cmd == snapshotCmd {
				helpCmd = snapshotGetCmd
			} else if cmd == deviceCmd {
				helpCmd = deviceGetCmd
			} else if cmd == adapterCmd {
				helpCmd = adapterGetTypesCmd
			}
			helpCmd.Help()

			panic(&PrintedErrorPanic{})
		}
	}
}
Exemple #29
0
func (o *NewProjectOptions) complete(cmd *cobra.Command, f *clientcmd.Factory) error {
	args := cmd.Flags().Args()
	if len(args) != 1 {
		cmd.Help()
		return errors.New("must have exactly one argument")
	}

	o.ProjectName = args[0]

	o.ProjectOptions = &ProjectOptions{}
	o.ProjectOptions.PathOptions = cliconfig.NewPathOptions(cmd)
	if err := o.ProjectOptions.Complete(f, []string{""}, o.Out); err != nil {
		return err
	}

	return nil
}
Exemple #30
0
func Release(cmd *cobra.Command, args []string) {
	log.Verbose(verbose)

	if len(args) < 1 {
		// fmt.Fprintln(os.Stderr, "missing AppName")
		cmd.Usage()
		return
	}

	res := args[0]
	var v int
	var err error
	if len(args) == 2 {
		v, err = strconv.Atoi(args[1])
	} else {
		v = -1
	}

	if err != nil {
		if args[1] == "last" {
			v = -1
		} else {
			fmt.Fprintln(os.Stderr, "invalid version\n", cmd.Help())
			return
		}
	}

	err = nil
	stub, err := pub.GetStubAndLoginFromCfg(cfg, &info)
	if err != nil {
		fmt.Fprintln(os.Stderr, err.Error())
		return
	}

	if !relRes {
		err = ReleaseManifest(stub, info.ID, res, v)

	} else {
		err = ReleaseRes(stub, info.ID, res, v)
	}

	if err != nil {
		fmt.Fprintln(os.Stderr, err.Error())
	}
}