convcmd

package
v0.0.0-...-9c55465 Latest Latest
Warning

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

Go to latest
Published: Apr 10, 2024 License: MIT Imports: 11 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ConvBaseCmd = &gcli.Command{
	Name:    "conv-base",
	Aliases: []string{"base", "cb"},
	Desc:    "Convert base data type. eg: binary, decimal(10), base8, hex(16), base64, base32 ...",
	Config: func(c *gcli.Command) {

		c.MustFromStruct(&convBaseOpts)
		c.AddArg("input", "want convert base string contents")
	},
	Func: func(c *gcli.Command, _ []string) (err error) {
		str := c.Arg("input").String()
		str, err = apputil.ReadSource(str)
		if err != nil {
			return err
		}

		c.Infoln("Input String:", str)
		c.Warnln("Conv Results:")
		commonBases := []int{2, 10, 16, 32, 36, 62, 64}
		if convBaseOpts.To < 2 {
			for _, toBase := range commonBases {
				if toBase == convBaseOpts.From {
					continue
				}

				dst := strutil.BaseConv(str, convBaseOpts.From, toBase)
				fmt.Printf("convert to %d: %s\n", toBase, dst)
			}
		} else {
			dst := strutil.BaseConv(str, convBaseOpts.From, convBaseOpts.To)
			fmt.Printf("convert to %d: %s\n", convBaseOpts.To, dst)
		}

		return
	},
}

ConvBaseCmd command Base Binary decimal Base 8

Functions

func NewConvPathSepCmd

func NewConvPathSepCmd() *gcli.Command

NewConvPathSepCmd instance

func NewDate2tsCmd

func NewDate2tsCmd() *gcli.Command

NewDate2tsCmd instance

func NewTime2dateCmd

func NewTime2dateCmd() *gcli.Command

NewTime2dateCmd instance

Types

This section is empty.

Jump to

Keyboard shortcuts

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