cmd

package
v0.0.0-...-4266db3 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 25, 2024 License: MIT Imports: 23 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var RootCmd = &cobra.Command{
	Use:     `jcloud`,
	Aliases: []string{"jc"},
	Short:   `Cloud is a cloud file manager CLI`,
	GroupID: "",
	Long: `Cloud is a cloud file manager CLI that provides various commands to manage files in the cloud.
It supports commands like init to initialize the cloud, addFile to addFile files, and exit to exit the CLI.`,
	Version: "0.0.1",
	PersistentPreRunE: func(cmd *cobra.Command, args []string) error {
		var ok bool
		a, ok = jctx.FromContext[*app.ClientContext](ctx, "app-context")
		if !ok {
			return fmt.Errorf("failed to get file context")
		}

		c = a.Cfg

		if versionFlag || cmd.Name() == "login" || cmd == cmd.Root() {
			return nil
		}

		content, err := io.ReadAll(a.Paths.P.JcloudFile)
		if err != nil {
			return fmt.Errorf("failed to read login file: %v", err)
		}

		if len(content) == 0 {
			hintMessage := h.DisplayHint("login", h.LoginRequired, c)
			if hintMessage != "" {
				cobra.WriteStringAndCheck(os.Stdout, hintMessage)
			}
			os.Exit(0)
		}

		return nil
	},

	Run: func(cmd *cobra.Command, args []string) {
		if versionFlag {
			cobra.WriteStringAndCheck(os.Stdout, cmd.Version)
		} else {
			err := cmd.Help()
			if err != nil {
				cobra.CheckErr(err)
			}
			return
		}
	},
}

Functions

func Execute

func Execute()

func SetContext

func SetContext(newCtx context.Context)

Types

This section is empty.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL