示例#1
0
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))
	}
}
示例#2
0
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
}
示例#3
0
/*
	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++
示例#4
0
	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) {
示例#5
0
文件: lns.go 项目: chengguozhen/clive
/*
	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
		}
示例#6
0
文件: mvf.go 项目: chengguozhen/clive
	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
		}
示例#7
0
文件: zxpull.go 项目: fjballest/clive
	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")
示例#8
0
文件: eco.go 项目: chengguozhen/clive
	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)
示例#9
0
文件: web.go 项目: fjballest/clive
/*
	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:
示例#10
0
文件: zxrepl.go 项目: fjballest/clive
	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 {
示例#11
0
文件: auth.go 项目: fjballest/clive
	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)
示例#12
0
文件: ch.go 项目: chengguozhen/clive
	"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
示例#13
0
	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
}
示例#14
0
*/
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
示例#15
0
文件: xzx.go 项目: fjballest/clive
	"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)
示例#16
0
	"clive/zx/rfs"
	"fmt"
	"os"
	"path"
	"path/filepath"
	"strings"
)

var (
	Verbose                     = true
	Persist, Debug, Zdebug, New bool

	Dprintf = dbg.FlagPrintf(os.Stdout, &Debug)
	Vprintf = dbg.FlagPrintf(os.Stdout, &Verbose)

	opts  = opt.New("spec... ***DEPRECATED***")
	port  string
	wport string
	svc   string
	addr  string

	zxw = map[string]string{}
)

func zxwax() {
	ctrl := ctl.NewControl()
	ctrl.BoolFlag("Debug", &Debug)
	ctrl.CmdFlag("Exit", func() {
		dbg.Fatal("exiting at user request")
	})
	wax.ServeLogin("/", "/index")
示例#17
0
	"clive/cmd"
	"clive/cmd/opt"
	"clive/dbg"
	"clive/u"
	"clive/zx/zux"
	fpath "path"
	"strings"
)

var (
	Dump    string
	Xcludes []string
	Once    bool
	Skip    bool

	opts    = opt.New("{file|name!file}")
	vprintf = cmd.VWarn
	dprintf = cmd.Dprintf
)

func main() {
	cmd.UnixIO()
	c := cmd.AppCtx()
	dfltdump := Path(u.Home, "dump")
	opts.NewFlag("s", "don't dump right now, wait until next at 5am", &Skip)
	opts.NewFlag("1", "dump once and exit", &Once)
	opts.NewFlag("v", "verbose", &c.Verb)
	opts.NewFlag("D", "debug", &c.Debug)
	opts.NewFlag("x", "expr: files excluded (.*, tmp.* if none given); tmp always excluded.", &Xcludes)
	Dump = dfltdump
	opts.NewFlag("d", "dir: where to keep the dump, ~/dump if none", &Dump)
示例#18
0
文件: when.go 项目: fjballest/clive
/*
	Notify the user or run commands when files change
*/
package main

import (
	"clive/cmd"
	"clive/cmd/opt"
	"clive/fswatch"
	"os/exec"
	"strings"
)

var (
	opts        = opt.New("file [cmd...]")
	notux, once bool
)

func kq(dir, wcmd string) {
	w, err := fswatch.New()
	if err != nil {
		cmd.Fatal("kqueue: %s", err)
	}

	cmd.Dprintf("(re)read %s\n", dir)
	if err := w.Add(dir); err != nil {
		cmd.Fatal("kqueue: %s", err)
	}
	if err != nil {
		cmd.Fatal("watch: %s", err)
	}