command

package
v0.0.0-...-bc672fa Latest Latest
Warning

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

Go to latest
Published: Mar 10, 2022 License: MIT Imports: 19 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	CosCmd = &cobra.Command{
		Use:   "cos",
		Short: "Cos Command:\t Just run `cli cos put/get sth.(file)`",
		Args: func(cmd *cobra.Command, args []string) error {
			if !checkArgs(args, 2, 2) {
				return fmt.Errorf("error args length")
			}
			return nil
		},
		Run: func(cmd *cobra.Command, args []string) {
			op, arg := parseCosAgrs(args)
			switch op {
			case "put":
				file, data := processReadFile(arg)
				if len(file) != 0 {
					handleResp(node.Cos.CosPut(context.Background(), &cos_pb.CosPutReq{
						FileName:  file,
						FileBytes: data,
					}))
				} else {
					log.Printf(errorReadFile, file, data)
				}
			case "get":
				log.Printf("Error: Not support `get`.\n")

			default:
				log.Printf(errorOpInvalid)
			}
		},
	}
)
View Source
var (
	CryptoCmd = &cobra.Command{
		Use:   "crypto",
		Short: "Crypto Command:\t Just run `cli crypto encrypt/decrypt BASE64/AES/DES sth.(string)`",
		Args: func(cmd *cobra.Command, args []string) error {
			if !checkArgs(args, 3, 0) {
				return fmt.Errorf("error args length")
			}
			return nil
		},
		Run: func(cmd *cobra.Command, args []string) {
			op, algo, text := parseCryptoAgrs(args)
			switch op {
			case "encrypt":
				handleResp(node.Crypto.CryptoEncrypt(context.Background(), &crypto_pb.CryptoEncryptReq{
					Algorithm: algo,
					PlainText: text,
				}))
			case "decrypt":
				handleResp(node.Crypto.CryptoDecrypt(context.Background(), &crypto_pb.CryptoDecryptReq{
					Algorithm:   algo,
					EncryptText: text,
				}))
			default:
				log.Printf(errorOpInvalid)
			}
		},
	}
)
View Source
var (
	PastebinCmd = &cobra.Command{
		Use:   "pastebin",
		Short: "PasteBin Command:\t Just run `cli pastebin submit sth.(file)`",
		Args: func(cmd *cobra.Command, args []string) error {
			if !checkArgs(args, 2, 2) {
				return fmt.Errorf("error args length")
			}
			return nil
		},
		Run: func(cmd *cobra.Command, args []string) {
			op, file := parsePastebinAgrs(args)
			switch op {
			case "submit":
				file, data := processReadFile(file)
				if len(file) != 0 {
					handleResp(node.Pastebin.PastebinSubmit(context.Background(), &pastebin_pb.PastebinSubmitReq{
						Text: string(data),
					}))
				} else {
					log.Printf(errorReadFile, file, data)
				}

			default:
				log.Printf(errorOpInvalid)
			}
		},
	}
)
View Source
var (
	RootCmd = &cobra.Command{
		Use:   "root",
		Short: "Terminal client for https://binacs.cn\nMore at https://github.com/BinacsLee/cli",
		PersistentPreRunE: func(cmd *cobra.Command, args []string) (err error) {
			conn, err := grpc.Dial(util.GetSockPath(),
				grpc.WithBlock(),
				grpc.WithInsecure(),
				grpc.WithDialer(unixConnect),
				grpc.FailOnNonTempDialError(true),
				grpc.WithDefaultCallOptions(grpc.MaxCallRecvMsgSize(types.GrpcMsgSize)),
				grpc.WithDefaultCallOptions(grpc.MaxCallSendMsgSize(types.GrpcMsgSize)),
			)
			if err != nil {
				return err
			}
			node = service.InitService(conn)
			return nil
		},
	}
)
View Source
var (
	TinyurlCmd = &cobra.Command{
		Use:   "tinyurl",
		Short: "TinyURL Command:\t Just run `cli tinyurl encode/decode sth.`",
		Args: func(cmd *cobra.Command, args []string) error {
			if !checkArgs(args, 2, 2) {
				return fmt.Errorf("error args length")
			}
			return nil
		},
		Run: func(cmd *cobra.Command, args []string) {
			op, url := parseTinyurlAgrs(args)
			switch op {
			case "encode":
				handleResp(node.TinyURL.TinyURLEncode(context.Background(), &tinyurl_pb.TinyURLEncodeReq{
					Url: url,
				}))
			case "decode":
				handleResp(node.TinyURL.TinyURLDecode(context.Background(), &tinyurl_pb.TinyURLDecodeReq{
					Turl: url,
				}))
			default:
				log.Printf(errorOpInvalid)
			}
		},
	}
)
View Source
var (
	UserCmd = &cobra.Command{
		Use:   "user",
		Short: "User Command:\t Just run `cli user test/register/auth/refresh/info`",
		Args: func(cmd *cobra.Command, args []string) error {
			if !checkArgs(args, 0, 0) {
				return fmt.Errorf("error args length")
			}
			return nil
		},
		Run: func(cmd *cobra.Command, args []string) {
			op, arg := parseUserAgrs(args)
			switch op {
			case "test":
				handleResp(node.User.UserTest(context.Background(), &user_pb.UserTestReq{}))
			case "register":
				if checkArgLength(arg, 2) {
					handleResp(node.User.UserRegister(context.Background(), &user_pb.UserRegisterReq{
						Id:  arg[0],
						Pwd: arg[1],
					}))
				}
			case "auth":
				if checkArgLength(arg, 2) {
					handleResp(node.User.UserAuth(context.Background(), &user_pb.UserAuthReq{
						Id:  arg[0],
						Pwd: arg[1],
					}))
				}
			case "refresh":
				if checkArgLength(arg, 1) {
					handleResp(node.User.UserRefresh(context.Background(), &user_pb.UserRefreshReq{
						RefreshToken: arg[0],
					}))
				}
			case "info":
				if checkArgLength(arg, 1) {
					handleResp(node.User.UserInfo(context.Background(), &user_pb.UserInfoReq{
						AccessToken: arg[0],
					}))
				}
			default:
				log.Printf(errorOpInvalid)
			}
		},
	}
)
View Source
var (
	VersionCmd = &cobra.Command{
		Use:   "version",
		Short: "Version Command",
		Run: func(cmd *cobra.Command, args []string) {
			log.Printf("Version: %s.%s.%s, CommitHash: %s\n", version.Maj, version.Min, version.Fix, version.GitCommit)
		},
	}
)

Functions

This section is empty.

Types

This section is empty.

Jump to

Keyboard shortcuts

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