ext

package
v0.0.1 Latest Latest
Warning

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

Go to latest
Published: May 21, 2016 License: MIT Imports: 12 Imported by: 0

Documentation

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

func InstallBashCompletion

func InstallBashCompletion(root *cli.Command) error

InstallBashCompletion install bash_completion

Types

type CSVRecord

type CSVRecord struct {
	// contains filtered or unexported fields
}

CSV reads one csv record

func (CSVRecord) Bools

func (d CSVRecord) Bools() ([]bool, error)

func (*CSVRecord) Decode

func (d *CSVRecord) Decode(s string) error

func (CSVRecord) Floats

func (d CSVRecord) Floats() ([]float64, error)

func (CSVRecord) Ints

func (d CSVRecord) Ints() ([]int64, error)

func (CSVRecord) Strings

func (d CSVRecord) Strings() []string

func (CSVRecord) Uints

func (d CSVRecord) Uints() ([]uint64, error)

type Duration

type Duration struct {
	time.Duration
}

Duration wrap time.Duration

Example

This example demonstrates uage of Duration decoder

package main

import (
	"github.com/mkideal/cli"
	"github.com/mkideal/cli/ext"
)

func main() {
	type argT struct {
		Duration ext.Duration `cli:"d"`
	}
	for _, args := range [][]string{
		[]string{"app", "-d10s"},
		[]string{"app", "-d10ms"},
	} {
		cli.RunWithArgs(new(argT), args, func(ctx *cli.Context) error {
			argv := ctx.Argv().(*argT)
			ctx.String("duration=%v\n", argv.Duration.Duration)
			return nil
		})
	}
}
Output:

duration=10s
duration=10ms

func (*Duration) Decode

func (d *Duration) Decode(s string) error

func (Duration) Encode

func (d Duration) Encode() string

type File

type File struct {
	// contains filtered or unexported fields
}

File reads data from file or stdin(if filename is empty)

Example

This example demonstrates usage of File decoder

package main

import (
	"io/ioutil"
	"os"

	"github.com/mkideal/cli"
	"github.com/mkideal/cli/ext"
)

func main() {
	type argT struct {
		Data ext.File `cli:"f"`
	}
	filename := "test.txt"
	ioutil.WriteFile(filename, []byte("hello, File decoder"), 0644)
	defer os.Remove(filename)

	args := []string{"app", "-f", filename}
	cli.RunWithArgs(new(argT), args, func(ctx *cli.Context) error {
		argv := ctx.Argv().(*argT)
		ctx.String("%s\n", argv.Data)
		return nil
	})
}
Output:

hello, File decoder

func (File) Data

func (f File) Data() []byte

func (*File) Decode

func (f *File) Decode(s string) error

func (File) Encode

func (f File) Encode() string

func (File) String

func (f File) String() string

type PidFile

type PidFile struct {
	// contains filtered or unexported fields
}

PidFile

func (*PidFile) Decode

func (pid *PidFile) Decode(s string) error

func (*PidFile) New

func (pid *PidFile) New() error

func (PidFile) Remove

func (pid PidFile) Remove() error

func (PidFile) String

func (pid PidFile) String() string

type Time

type Time struct {
	time.Time
	// contains filtered or unexported fields
}

Time wrap time.Time

Example

This example demonstrates usage of Time decoder

package main

import (
	"time"

	"github.com/mkideal/cli"
	"github.com/mkideal/cli/ext"
)

func main() {
	type argT struct {
		When ext.Time `cli:"w"`
	}
	for _, args := range [][]string{
		[]string{"app", "-w", "2016-01-02 12:12:22"},
		[]string{"app", "-w2016-01-02"},
	} {
		cli.RunWithArgs(new(argT), args, func(ctx *cli.Context) error {
			argv := ctx.Argv().(*argT)
			ctx.String("time=%s\n", argv.When.Time.Format(time.ANSIC))
			return nil
		})
	}
}
Output:

time=Sat Jan  2 12:12:22 2016
time=Sat Jan  2 00:00:00 2016

func (*Time) Decode

func (t *Time) Decode(s string) error

func (Time) Encode

func (t Time) Encode() string

func (Time) IsSet

func (t Time) IsSet() bool

Jump to

Keyboard shortcuts

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