當前位置: 首頁>>代碼示例>>Golang>>正文


Golang opt.New函數代碼示例

本文整理匯總了Golang中clive/cmd/opt.New函數的典型用法代碼示例。如果您正苦於以下問題:Golang New函數的具體用法?Golang New怎麽用?Golang New使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。


在下文中一共展示了New函數的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。

示例1: main

func main() {
	opts := opt.New("[file]")
	c := cmd.AppCtx()
	opts.NewFlag("D", "debug", &c.Debug)
	rdonly := false
	opts.NewFlag("r", "read only", &rdonly)
	opts.NewFlag("e", "do edits for testing", &doedits)
	cmd.UnixIO("err")
	args := opts.Parse()
	var t *ink.Txt
	inkout := cmd.Out("ink")
	if inkout == nil {
		cmd.UnixIO()
	}
	if len(args) == 0 {
		t = ink.NewTxt("1234", "abc")
	} else {
		dat, err := zx.GetAll(cmd.NS(), cmd.AbsPath(args[0]))
		if err != nil {
			cmd.Fatal(err)
		}
		t = ink.NewTxt(args[0]+" Del", string(dat))
	}
	go edit(t)
	if rdonly {
		t.NoEdits()
	}
	ink.UsePort("8182")
	bs := ink.NewButtonSet(&ink.Button{Tag: "One", Name: "one"},
		&ink.Button{Tag: "Two", Name: "two"},
		&ink.Button{Tag: "B", Name: "b", Value: &bold},
		&ink.Button{Tag: "I", Name: "i", Value: &italic})
	rs := ink.NewRadioSet(&style, &ink.Button{Tag: "R", Name: "r"},
		&ink.Button{Tag: "T", Name: "t"})
	go buttons(bs, rs, t)

	pg := ink.NewPg("/", "Example text editing:", bs, rs, t)
	pg.Tag = "Clive's iedit"
	if doedits {
		go edits(t)
	}
	go ink.Serve()
	if inkout != nil {
		// TODO: ctlrs must use unique ids sytem-wide, or
		// controls written won't work because of their ids.
		inkout <- []byte(`<tt>Hi there, this is HTML</tt>`)
		var buf bytes.Buffer
		bs.WriteTo(&buf)
		inkout <- buf.Bytes()
		inkout <- []byte("https://localhost:8182")
	}
	t.Wait()
	for rs := range t.Get(0, -1) {
		cmd.Printf("%s", string(rs))
	}
}
開發者ID:chengguozhen,項目名稱:clive,代碼行數:56,代碼來源:iedit.go

示例2: Run

func Run(c cmd.Ctx) (err error) {
	argv := c.Args
	x := &xCmd{Ctx: &c}
	x.Flags = opt.New("expr")
	debugLex = false
	bhelp := false
	x.NewFlag("F", "report known functions and exit", &bhelp)
	x.NewFlag("D", "debug", &debugLex)
	x.NewFlag("q", "do not print values as they are evaluated", &x.quiet)
	x.Argv0 = argv[0]
	args, err := x.Parse(argv)
	if err != nil {
		x.Usage(x.Stderr)
		return err
	}
	cmd.MkNS()
	if bhelp {
		fns := []string{}
		for k := range funcs {
			fns = append(fns, k)
		}
		sort.Sort(sort.StringSlice(fns))
		for _, b := range fns {
			x.Printf("%s\n", b)
		}
		return nil
	}
	if len(args) != 0 {
		expr := strings.Join(args, " ")
		return x.expr(expr)
	}
	var sts error
	scn := bufio.NewScanner(x.Stdin)
	for scn.Scan() {
		ln := scn.Text()
		if ln == "" {
			continue
		}
		if err := x.expr(ln); err != nil {
			sts = errors.New("errors")
			x.Warn("'%s': %s", ln, err)
		}
	}
	if err := scn.Err(); err != nil {
		x.Warn("%s", err)
		sts = errors.New("errors")
	}
	if x, ok := result.(bool); sts==nil && ok {
		if x {
			return nil
		}
		return errors.New("false")
	}
	return sts
}
開發者ID:Christopheraburns,項目名稱:clive,代碼行數:55,代碼來源:xp.go

示例3: replre

/*
	translate expressions in input
*/
package main

import (
	"clive/cmd"
	"clive/cmd/opt"
	"clive/sre"
	"strings"
)

var (
	opts       = opt.New("to | {from to}")
	res        []*sre.ReProg
	froms, tos []string
	all        bool

	sflag, fflag, gflag, tflag, lflag, uflag, rflag, xflag bool
)

func replre(s string, re *sre.ReProg, to string, glob bool) string {
	rfrom := []rune(s)
	rto := []rune(to)
	nrefs := 0
	for i := 0; i < len(rto)-1; i++ {
		if nb := rto[i+1]; rto[i] == '\\' {
			if nb >= '0' && nb <= '9' {
				nb -= '0'
				rto[i] = nb
				nrefs++
開發者ID:chengguozhen,項目名稱:clive,代碼行數:31,代碼來源:trex.go

示例4: main

	Clean and print path or path elements
*/
package main

import (
	"clive/cmd"
	"clive/cmd/opt"
	fpath "path"
	"path/filepath"
)

var (
	ux, dflag, bflag bool

	dir  string
	opts = opt.New("{name}")
)

// Run path in the current app context.
func main() {
	cmd.UnixIO("err")
	c := cmd.AppCtx()
	opts.NewFlag("D", "debug", &c.Debug)
	opts.NewFlag("r", "dir: print paths relative to dir", &dir)
	opts.NewFlag("d", "print parent directories", &dflag)
	opts.NewFlag("b", "print base names", &bflag)
	args := opts.Parse()
	if ux {
		cmd.UnixIO()
	}
	if dir != "" && (dflag || bflag) {
開發者ID:chengguozhen,項目名稱:clive,代碼行數:31,代碼來源:path.go

示例5: parseRanges

/*
	print lines in input
*/
package main

import (
	"clive/cmd"
	"clive/cmd/opt"
	"clive/zx"
)

var (
	opts            = opt.New("{file}")
	all             bool
	pflag, nflag    bool
	nhd, ntl, nfrom int
	ranges          []string
	addrs           []opt.Range
)

func parseRanges() error {
	for _, r := range ranges {
		a, err := opt.ParseRange(r)
		if err != nil {
			return err
		}
		from, to := a.P0, a.P1
		addrs = append(addrs, a)
		if from > 0 && nhd < from {
			nhd = from
		}
開發者ID:chengguozhen,項目名稱:clive,代碼行數:31,代碼來源:lns.go

示例6: dst

	mv a b... c takes c as the target parent dir for a, b...
*/
package main

import (
	"clive/cmd"
	"clive/cmd/opt"
	"clive/zx"
	"errors"
	"fmt"
	fpath "path"
	"strings"
)

var (
	opts           = opt.New("[src] dst | src1 src2... dstdir")
	todir, dry, ux bool
)

func dst(name string) (zx.Dir, error) {
	if strings.Contains(name, ",") {
		return nil, errors.New("destination can't be a predicate")
	}
	d, err := cmd.Stat(name)
	if zx.IsNotExist(err) {
		path := cmd.AbsPath(name)
		ppath := fpath.Dir(path)
		pd, err := cmd.Stat(ppath)
		if err != nil {
			return nil, err
		}
開發者ID:chengguozhen,項目名稱:clive,代碼行數:31,代碼來源:mvf.go

示例7: main

	if err != nil {
		cmd.Warn("/u/lib/repl: %s", err)
		return nil
	}
	nms := []string{}
	for _, d := range ds {
		if nm := d.Name(); strings.HasSuffix(nm, ".ldb") {
			nm = nm[:len(nm)-4]
			nms = append(nms, nm)
		}
	}
	return nms
}

var (
	opts                       = opt.New("file")
	notux, aflag, bflag, nflag bool
)

func main() {
	cmd.UnixIO("err")
	c := cmd.AppCtx()
	opts.NewFlag("D", "debug", &c.Debug)
	opts.NewFlag("v", "verbose", &c.Verb)
	opts.NewFlag("a", "all", &aflag)
	opts.NewFlag("b", "blind", &bflag)
	opts.NewFlag("n", "dry run", &nflag)
	opts.NewFlag("u", "don't use unix out", &notux)
	args := opts.Parse()
	if !notux {
		cmd.UnixIO("out")
開發者ID:fjballest,項目名稱:clive,代碼行數:31,代碼來源:zxpull.go

示例8: main

	sends output to a named chan and/or gets input from a named chan.
*/
package main

import (
	"bytes"
	"clive/cmd"
	"clive/cmd/opt"
)

var (
	nflag, mflag bool
	ux           bool
	oname        = "out"
	iname        string
	opts         = opt.New("{arg}")
)

// Run echo in the current app context.
func main() {
	cmd.UnixIO("err")
	c := cmd.AppCtx()
	opts.NewFlag("D", "debug", &c.Debug)
	opts.NewFlag("n", "don't add a final newline", &nflag)
	opts.NewFlag("m", "issue one message per arg", &mflag)
	opts.NewFlag("u", "use unix out", &ux)
	opts.NewFlag("o", "chan: output to this chan (for testing other tools)", &oname)
	opts.NewFlag("i", "chan: echo input from this chan (for testing other tools)", &iname)
	args := opts.Parse()
	if ux {
		cmd.UnixIO(oname)
開發者ID:chengguozhen,項目名稱:clive,代碼行數:31,代碼來源:eco.go

示例9: main

/*
	Simple static web server for UNIX files.
*/
package main

import (
	"clive/cmd"
	"clive/cmd/opt"
	"net/http"
)

var (
	dir   = "/zx/usr/web"
	port  = "8080"
	tport = "8083"
	opts  = opt.New("[dir]")
)

func main() {
	cmd.UnixIO()
	local := false
	opts.NewFlag("p", "port: port used (8080 by default)", &port)
	opts.NewFlag("t", "port: TLS port (8083 by default)", &tport)
	opts.NewFlag("l", "localhost and TLS only", &local)
	args := opts.Parse()
	switch len(args) {
	case 0:
		if local {
			dir = "/zx"
		}
	case 1:
開發者ID:fjballest,項目名稱:clive,代碼行數:31,代碼來源:web.go

示例10: main

	if err != nil {
		cmd.Warn("/u/lib/repl: %s", err)
		return nil
	}
	nms := []string{}
	for _, d := range ds {
		if nm := d.Name(); strings.HasSuffix(nm, ".ldb") {
			nm = nm[:len(nm)-4]
			nms = append(nms, nm)
		}
	}
	return nms
}

var (
	opts                = opt.New("[file [ldir rdir]]")
	excl                []string
	notux, nflag, mflag bool
)

func main() {
	cmd.UnixIO("err")
	c := cmd.AppCtx()
	opts.NewFlag("D", "debug", &c.Debug)
	opts.NewFlag("v", "verbose", &c.Verb)
	opts.NewFlag("x", "exclude", &excl)
	opts.NewFlag("n", "print just replica names when used to list replicas", &nflag)
	opts.NewFlag("m", "move existing replica client/server paths to the given ones", &mflag)
	opts.NewFlag("u", "don't use unix out", &notux)
	args := opts.Parse()
	if !notux {
開發者ID:fjballest,項目名稱:clive,代碼行數:31,代碼來源:zxrepl.go

示例11: main

	Under flag -f it rewrites the key file even if it exists.
*/
package main

import (
	"clive/cmd"
	"clive/cmd/opt"
	"clive/net/auth"
	"os"
)

var (
	dir   string
	force bool
	opts  = opt.New("name user secret [group...]")
)

func main() {
	cmd.UnixIO()
	dfltdir := auth.KeyDir()
	dir = dfltdir
	opts.NewFlag("d", "adir: clive auth dir", &dir)
	opts.NewFlag("f", "force write of key file when file already exists", &force)
	args := opts.Parse()
	if len(args) < 3 {
		opts.Usage()
	}
	name, user, secret := args[0], args[1], args[2]
	groups := args[3:]
	file := auth.KeyFile(dir, name)
開發者ID:fjballest,項目名稱:clive,代碼行數:30,代碼來源:auth.go

示例12: size

	"strings"
)

var units = map[uint8]uint64{
	'b': 1,
	'B': 1,
	'k': 1024,
	'K': 1024,
	'm': 1024 * 1024,
	'M': 1024 * 1024,
	'g': 1024 * 1024,
	'G': 1024 * 1024 * 1024,
}

var (
	opts = opt.New("{attr value}")
)

func size(val string) string {
	if len(val) <= 1 {
		return val
	}
	n := len(val)
	unit := val[n-1]
	u, ok := units[unit]
	if !ok {
		return val
	}
	nb, err := strconv.ParseUint(val[:n-1], 0, 64)
	if err != nil {
		return val
開發者ID:chengguozhen,項目名稱:clive,代碼行數:31,代碼來源:ch.go

示例13: serveFor

	fs "clive/fuse"
	"clive/x/bazil.org/fuse"
)

var (
	addr         string
	mntdir       = "/n/zx"
	rflag, sflag bool
	zdebug       bool
	delayed      bool
	nocaching    bool
	mfscfs       bool
	lfsdir       string
	xaddr        string
	opts         = opt.New("addr|dir [mntdir] & ***DEPRECATED***")
	dprintf      = dbg.FlagPrintf(os.Stderr, &zxfs.Debug)
)

func serveFor(t zx.Tree, c nchan.Conn) {
	ai, err := auth.AtServer(c, "", "zx", "finder")
	if err != nil && err != auth.ErrDisabled {
		dbg.Warn("auth %s: %s\n", c.Tag, err)
		close(c.In, err)
		close(c.Out, err)
		return
	}
	srv := rfs.Serve("rfs:"+c.Tag, c, ai, rflag, t)
	srv.Debug = false
}
開發者ID:Christopheraburns,項目名稱:clive,代碼行數:29,代碼來源:zxfs.go

示例14: interactive

*/
package main

import (
	"bufio"
	"bytes"
	"clive/cmd"
	"clive/cmd/opt"
	"clive/dbg"
	"io/ioutil"
	"os"
)

var (
	cmdarg               string
	opts                 = opt.New("[file [arg...]]")
	debug, verb, debugNs bool
	dprintf              = dbg.FlagPrintf(os.Stderr, &debug)
	vprintf              = dbg.FlagPrintf(os.Stderr, &verb)
	Interactive          bool
	lexer                *lex
	Prompter             *cmd.Reader
)

func interactive(in *bufio.Reader) (isintr bool) {
	// if there's a C-c while we are reading,
	// the lexer will panic with ErrIntr,
	// to signal us that we must discard the current
	// input and parsing and start again.
	defer func() {
		lvl = 0
開發者ID:Christopheraburns,項目名稱:clive,代碼行數:31,代碼來源:ql.go

示例15: main

	"clive/zx"
	"clive/zx/rzx"
	"clive/zx/zux"
	"clive/zx/zxc"
	fpath "path"
	"path/filepath"
	"strings"
)

var (
	noauth, wsync bool
	Zdebug        bool
	dprintf       = cmd.Dprintf
	vprintf       = cmd.VWarn

	opts       = opt.New("{spec}")
	port, addr string
)

func main() {
	cmd.UnixIO()
	opts.AddUsage("\tspec is name | name!file | name!file!flags \n")
	opts.AddUsage("\tspec flags are ro | rw | ncro | ncrw \n")
	port = "8002"
	addr = "*!*!zx"
	opts.NewFlag("p", "port: tcp server port (8002 by default)", &port)
	opts.NewFlag("a", "addr: service address (*!*!zx by default)", &addr)
	opts.NewFlag("s", "use writesync for caches", &wsync)
	c := cmd.AppCtx()
	opts.NewFlag("D", "debug", &c.Debug)
	opts.NewFlag("A", "auth debug", &auth.Debug)
開發者ID:fjballest,項目名稱:clive,代碼行數:31,代碼來源:xzx.go


注:本文中的clive/cmd/opt.New函數示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。