Exemplo n.º 1
0
Arquivo: main.go Projeto: unixdj/xd
// setDumperValue returns a conf.Value whose Set method sets
// g.dumper to v.
func setDumperValue(v int) conf.Value {
	return conf.FuncValue(func(string) error {
		if g.dumper != 0 {
			return errors.New("-b, -C, -G, -o and -r are incompatible")
		}
		g.dumper = v
		return nil
	})
}
Exemplo n.º 2
0
Arquivo: main.go Projeto: unixdj/xd
func parseFlags() []string {
	var vars = []conf.Var{
		{Flag: 'h', Kind: conf.NoArg, Val: conf.FuncValue(help)},
		{Flag: 'b', Kind: conf.NoArg, Val: setDumperValue(BinDumper)},
		{Flag: 'o', Kind: conf.NoArg, Val: setDumperValue(OctDumper)},
		{Flag: 'C', Kind: conf.NoArg, Val: setDumperValue(CDumper)},
		{Flag: 'G', Kind: conf.NoArg, Val: setDumperValue(GoDumper)},
		{Flag: 'r', Kind: conf.NoArg, Val: setDumperValue(Undumper)},
		{Flag: 'e', Kind: conf.NoArg, Val: (*conf.BoolValue)(&g.le)},
		{Flag: 'c', Val: (*smallValue)(&g.cols)},
		{Flag: 'g', Val: (*smallValue)(&g.group)},
		{Flag: 'l', Val: (*int63Value)(&g.length)},
		{Flag: 'd', Val: (*conf.Int64Value)(&g.pos)},
		{Flag: 's', Val: (*conf.Int64Value)(&g.seek)},
		{Flag: 'O', Val: (*conf.StringValue)(&g.outfile)},
		{Flag: 'P', Val: (*conf.StringValue)(&g.pkg)},
		{Flag: 'V', Val: (*conf.StringValue)(&g.ident)},
	}
	if err := conf.GetOpt(vars); err != nil {
		os.Stderr.WriteString(err.Error() + "\n")
		help("")
	}
	if g.dumper == Undumper {
		g.rev = true
		if g.le {
			os.Stderr.WriteString("-e and -r are incompatible\n")
			help("")
		}
	} else {
		if g.cols == 0 {
			g.cols = dumpers[g.dumper].defCols
		}
		if g.group == 0 {
			g.group = dumpers[g.dumper].defGroup
		}
		if g.ident == "" && len(conf.Args) != 0 {
			g.ident = makeIdent(conf.Args[0])
		}
	}
	return conf.Args
}