ext

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Feb 9, 2020 License: MIT Imports: 15 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/franchb/cli"
	"github.com/franchb/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/franchb/cli"
	"github.com/franchb/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 string

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 Reader added in v0.0.2

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

Reader

func (Reader) Close added in v0.0.2

func (r Reader) Close() error

func (*Reader) Decode added in v0.0.2

func (r *Reader) Decode(s string) error

func (Reader) IsStdin added in v0.0.2

func (r Reader) IsStdin() bool

func (Reader) Name added in v0.0.2

func (r Reader) Name() string

func (Reader) Read added in v0.0.2

func (r Reader) Read(data []byte) (n int, err error)

Read implementes io.Reader

func (*Reader) SetReader added in v0.0.2

func (r *Reader) SetReader(reader io.Reader)

SetReader replaces the native reader

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/franchb/cli"
	"github.com/franchb/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

type Writer added in v0.0.2

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

Writer

func (*Writer) Close added in v0.0.2

func (w *Writer) Close() error

func (*Writer) Decode added in v0.0.2

func (w *Writer) Decode(s string) error

func (Writer) IsStdout added in v0.0.2

func (w Writer) IsStdout() bool

func (*Writer) Name added in v0.0.2

func (w *Writer) Name() string

func (*Writer) SetWriter added in v0.0.2

func (w *Writer) SetWriter(writer io.Writer)

SetWriter replaces the native writer

func (*Writer) Write added in v0.0.2

func (w *Writer) Write(data []byte) (n int, err error)

Write implementes io.Writer interface

Jump to

Keyboard shortcuts

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