Esempio n. 1
0
func validateContainerState(cmd *cobra.Command, args []string) {
	containerID, _ := cmd.Flags().GetString("id")

	if len(containerID) == 0 {
		cmd.HelpFunc()
		return
	}

	//FIXME: Instead of default as linux, detect os
	targetOS := "linux"

	plugin, err := plugin.NewPlugin(targetOS)
	if err != nil {
		log.Error(err)
		//fmt.Println(err)
		return
	}
	errors, valid := plugin.ValidatePluginState(containerID)
	if !valid {
		for _, err := range errors {
			//fmt.Println(err)
			log.Warn(err)
		}
		fmt.Printf("\nInvalid OCI State format\n")
	} else {
		fmt.Println("Container State Valid OCI")
	}

	return
}
Esempio n. 2
0
func validateContainerConfig(cmd *cobra.Command, args []string) {
	imagePath, _ := cmd.Flags().GetString("image")
	targetOS, _ := cmd.Flags().GetString("os")

	_, err := os.Stat(imagePath)
	if os.IsNotExist(err) {
		cmd.HelpFunc()
		return
	}
	//FIXME: Instead of default as linux, detect os

	plugin, err := plugin.NewPlugin(targetOS)
	if err != nil {
		//fmt.Println(err)
		log.Error(err)
		return
	}
	errors, valid := plugin.ValidatePluginSpecs(imagePath)
	if !valid {
		fmt.Println("")
		for _, err := range errors {
			log.Warn(err)
			//fmt.Println(err)
		}
		fmt.Printf("\nInvalid OCI config format\n")
	} else {
		fmt.Printf("\nConfig is Valid OCI\n")
	}
	return
}
Esempio n. 3
0
func cmdHostname(cmd *cobra.Command, args []string) {
	if len(args) == 0 {
		fmt.Printf("%s", MyAPIGet("hostname"))
	} else if len(args) == 1 {
		MyAPIPost("hostname", args[0])
	} else {
		cmd.HelpFunc()
	}
}
Esempio n. 4
0
func cmdDockerBip(cmd *cobra.Command, args []string) {
	if len(args) == 0 {
		fmt.Println(MyAPIGet("docker/bip"))
	} else if len(args) == 1 {
		MyAPIPost("docker/bip", args[0])
	} else {
		cmd.HelpFunc()
	}
}
Esempio n. 5
0
func preFlight(ccmd *cobra.Command, args []string) error {
	if config.Version {
		return fmt.Errorf(fmt.Sprintf("portal %s (%s)", tag, commit))
	}

	if !config.Server {
		ccmd.HelpFunc()(ccmd, args)
		return fmt.Errorf("") // no error, just exit
	}

	return nil
}
Esempio n. 6
0
func preFlight(ccmd *cobra.Command, args []string) error {
	if config.Version {
		fmt.Printf("logvac %s (%s)\n", tag, commit)
		return fmt.Errorf("")
	}

	if !config.Server {
		ccmd.HelpFunc()(ccmd, args)
		return fmt.Errorf("")
	}
	return nil
}
Esempio n. 7
0
func preFlight(ccmd *cobra.Command, args []string) error {
	if version {
		fmt.Printf("pulse %s (%s)\n", tag, commit)
		return fmt.Errorf("") // no error, just exit
	}

	if !viper.GetBool("server") {
		ccmd.HelpFunc()(ccmd, args)
		return fmt.Errorf("") // no error, just exit
	}

	return nil
}
Esempio n. 8
0
func preFlight(ccmd *cobra.Command, args []string) error {
	// if --version is passed print the version info
	if showVers {
		fmt.Printf("hoarder %s (%s)\n", version, commit)
		return fmt.Errorf("")
	}

	// if --server is not passed, print help
	if !viper.GetBool("server") {
		ccmd.HelpFunc()(ccmd, args)
		return fmt.Errorf("") // no error, just exit
	}

	return nil
}
func (a *annactl) ExecAnnactlControlLogResetLevelsCmd(cmd *cobra.Command, args []string) {
	a.Log.WithTags(spec.Tags{C: nil, L: "D", O: a, V: 13}, "call ExecAnnactlControlLogResetLevelsCmd")

	if len(args) > 0 {
		cmd.HelpFunc()(cmd, nil)
		os.Exit(1)
	}

	ctx := context.Background()

	err := a.LogControl.ResetLevels(ctx)
	if err != nil {
		a.Log.WithTags(spec.Tags{C: nil, L: "F", O: a, V: 1}, "%#v", maskAny(err))
	}
}
Esempio n. 10
0
func (a *annad) ExecAnnadCmd(cmd *cobra.Command, args []string) {
	a.Log.WithTags(spec.Tags{C: nil, L: "D", O: a, V: 13}, "call ExecAnnadCmd")

	if len(args) > 0 {
		cmd.HelpFunc()(cmd, nil)
		os.Exit(1)
	}

	a.Log.WithTags(spec.Tags{C: nil, L: "I", O: a, V: 10}, "booting annad")

	a.Log.WithTags(spec.Tags{C: nil, L: "I", O: a, V: 10}, "booting network")
	go a.Network.Boot()

	a.Log.WithTags(spec.Tags{C: nil, L: "I", O: a, V: 10}, "booting server")
	go a.Server.Boot()

	// Block the main goroutine forever. The process is only supposed to be ended
	// by a call to Shutdown or ForceShutdown.
	select {}
}
func (a *annactl) ExecAnnactlControlLogSetVerbosityCmd(cmd *cobra.Command, args []string) {
	a.Log.WithTags(spec.Tags{C: nil, L: "D", O: a, V: 13}, "call ExecAnnactlControlLogSetVerbosityCmd")

	if len(args) != 1 {
		cmd.HelpFunc()(cmd, nil)
		os.Exit(1)
	}

	ctx := context.Background()

	v, err := strconv.Atoi(args[0])
	if err != nil {
		a.Log.WithTags(spec.Tags{C: nil, L: "F", O: nil, V: 1}, "%#v", maskAny(err))
	}

	err = a.LogControl.SetVerbosity(ctx, v)
	if err != nil {
		a.Log.WithTags(spec.Tags{C: nil, L: "F", O: nil, V: 1}, "%#v", maskAny(err))
	}
}
func (a *annactl) ExecAnnactlInterfaceTextReadFileCmd(cmd *cobra.Command, args []string) {
	a.Log.WithTags(spec.Tags{C: nil, L: "D", O: a, V: 13}, "call ExecAnnactlInterfaceTextReadFileCmd")

	if len(args) == 0 || len(args) >= 2 {
		cmd.HelpFunc()(cmd, nil)
		os.Exit(1)
	}

	ctx := context.Background()

	b, err := a.Service().FS().ReadFile(args[0])
	if err != nil {
		a.Log.WithTags(spec.Tags{C: nil, L: "F", O: a, V: 1}, "%#v", maskAny(err))
	}

	textRequest := textinput.MustNew()
	err = json.Unmarshal(b, &textRequest)
	if err != nil {
		a.Log.WithTags(spec.Tags{C: nil, L: "F", O: a, V: 1}, "%#v", maskAny(err))
	}

	a.Service().TextInput().GetChannel() <- textRequest

	go func() {
		err = a.TextInterface.StreamText(ctx)
		if err != nil {
			a.Log.WithTags(spec.Tags{C: nil, L: "F", O: a, V: 1}, "%#v", maskAny(err))
		}
	}()

	for {
		select {
		case textResponse := <-a.Service().TextOutput().GetChannel():
			fmt.Printf("%s\n", textResponse.GetOutput())
		}
	}
}
Esempio n. 13
0
File: rkt.go Progetto: nak3/rkt
func runMissingCommand(cmd *cobra.Command, args []string) {
	stderr.Print("missing command")
	cmd.HelpFunc()(cmd, args)
	cmdExitCode = 2 // invalid argument
}
Esempio n. 14
0
func (a *annactl) ExecAnnactlInterfaceTextReadCmd(cmd *cobra.Command, args []string) {
	a.Log.WithTags(spec.Tags{C: nil, L: "D", O: a, V: 13}, "call ExecAnnactlInterfaceTextReadCmd")

	cmd.HelpFunc()(cmd, nil)
}
Esempio n. 15
0
File: cli.go Progetto: harche/docker
// ShowHelp shows the command help.
func (cli *DockerCli) ShowHelp(cmd *cobra.Command, args []string) error {
	cmd.SetOutput(cli.err)
	cmd.HelpFunc()(cmd, args)
	return nil
}
Esempio n. 16
0
func yochuRun(cmd *cobra.Command, args []string) {
	cmd.HelpFunc()(cmd, nil)
}
Esempio n. 17
0
func (a *annactl) ExecAnnactlControlLogResetCmd(cmd *cobra.Command, args []string) {
	a.Log.WithTags(spec.Tags{C: nil, L: "D", O: a, V: 13}, "call ExecAnnactlControlLogResetCmd")

	cmd.HelpFunc()(cmd, nil)
}
Esempio n. 18
0
File: search.go Progetto: zquestz/s
// 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(config.Verbose))
		return nil
	}

	if config.ListTags {
		fmt.Printf(providers.DisplayTags(config.Verbose))
		return nil
	}

	if config.ServerMode {
		err := server.Run(config.Port, config.Cert, config.Key, config.Provider, config.Verbose)
		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,
			config.Tag,
			query,
			cmd.Flags().Changed("provider"),
			config.Output,
			config.Verbose,
		)
		if err != nil {
			return err
		}
	} else {
		// Don't return an error, help screen is more appropriate.
		help := cmd.HelpFunc()
		help(cmd, args)
	}

	return nil
}