cmd

package
v1.17.1 Latest Latest
Warning

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

Go to latest
Published: Jan 19, 2023 License: MIT Imports: 20 Imported by: 1

README

some useful cmds.

Example:

append to your root cmd.

import (
	gcmd "github.com/Laisky/go-utils/cmd"
)

func init() {
	rootCmd.AddCommand(gcmd.EncryptCMD)
}

Documentation

Overview

Package cmd some useful tools for command argument

Index

Constants

This section is empty.

Variables

View Source
var EncryptAESCMD = &cobra.Command{
	Use:  "aes",
	Long: `encrypt file by aes`,
	PreRunE: func(cmd *cobra.Command, args []string) error {
		return setupEncryptAESArgs(cmd)
	},
	Run: func(cmd *cobra.Command, args []string) {
		fs, err := os.Stat(gutils.Settings.GetString("inputfile"))
		if err != nil {
			gutils.Logger.Panic("read path", zap.Error(err))
		}

		if fs.IsDir() {
			if err = encryptDirFileByAes(); err != nil {
				gutils.Logger.Panic("encrypt files in dir", zap.Error(err))
			}
		} else {
			if err = encryptFileByAes(); err != nil {
				gutils.Logger.Panic("encrypt file", zap.Error(err))
			}
		}
	},
}

EncryptAESCMD encrypt files by aes

`go run cmd/main/main.go encrypt aes -i cmd/root.go -s 123`
View Source
var EncryptCMD = &cobra.Command{
	Use:  "encrypt",
	Long: `encrypt file`,
	Args: NoExtraArgs,
	PreRunE: func(cmd *cobra.Command, args []string) error {
		return setupEncryptArgs(cmd)
	},
	Run: func(cmd *cobra.Command, args []string) {
	},
}

EncryptCMD encrypt files

View Source
var GenTLS = &cobra.Command{
	Use:   "gentls",
	Short: "generate tls cert",
	Args:  NoExtraArgs,
	PreRunE: func(cmd *cobra.Command, args []string) error {
		return setupTLSArgs(cmd, args)
	},
	Run: func(cmd *cobra.Command, args []string) {
		gutils.Logger.Info("run generateTLSCert")
		generateTLSCert()
	},
}

GenTLS 生成 tls 证书

`go run -race cmd/main/main.go gentls --host 1.2.3.4`

注,RSA 证书没毛病,P256 的 ES 证书 Chrome 尚不支持 inspired by https://golang.org/src/crypto/tls/generate_cert.go

Functions

func Execute

func Execute()

Execute adds all child commands to the root command and sets flags appropriately. This is called by main.main(). It only needs to happen once to the rootCmd.

func NoExtraArgs added in v1.13.8

func NoExtraArgs(cmd *cobra.Command, args []string) error

NoExtraArgs make sure every args has been processed

do not allow any unprocessed args

Example

use with cobra.Command:

cmd = &cobra.Command{
    Args: NoExtraArgs,
}

Types

This section is empty.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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