Ejemplo n.º 1
0
Archivo: flags.go Proyecto: etcenter/c4
func init() {
	id_message := versionString() + "\n\nUsage: c4 [mode] [flags] [files]\n\n" +
		"# `id` mode \n\n" +
		"    c4 generates c4ids for all files and folders spacified.\n" +
		"    If no file is given c4 will read piped data.\n" +
		"    Output is in YAML format.\n\n" +
		"  flags:\n"
	cp_message := "\n\n" +
		"# `cp` mode (not yet implemented)\n\n" +
		"    cp mode acts as a drop in replacement for the unix cp command.\n" +
		"    It acts the same as the normal cp command, but ids files on the fly\n" +
		"    It also adds the ability to specify multiple copy targets with the -T flag.\n\n" +
		"  flags:\n"
	flag.Usage = func() {
		fmt.Fprintf(os.Stderr, id_message)
		id_flags.PrintDefaults()
		fmt.Fprintf(os.Stderr, cp_message)
		cp_flags.PrintDefaults()
		fmt.Fprintf(os.Stderr, "\n")
	}

	id_flags = flag.NewFlagSet("id", flag.ContinueOnError)
	cp_flags = flag.NewFlagSet("cp", flag.ContinueOnError)

	// id
	// id_flags.BoolVarP(&version_flag, "version", "v", false, "Show version information.")
	id_flags.BoolVarP(&recursive_flag, "recursive", "R", false, "Recursively identify all files for the given url.")
	id_flags.BoolVarP(&absolute_flag, "absolute", "a", false, "Output absolute paths, instead of relative paths.")
	// id_flags.BoolVarP(&arg_links, "arg_links", "H", false, "If the -R option is specified, symbolic links on the command line are followed.\n          (Symbolic links encountered in the tree traversal are not followed by default.)")
	id_flags.BoolVarP(&links_flag, "links", "L", false, "All symbolic links are followed.")
	// id_flags.BoolVarP(&no_links, "no_links", "P", true, "If the -R option is specified, no symbolic links are followed.  This is the default.")
	id_flags.IntVarP(&depth, "depth", "d", 0, "Only output ids for files and folders 'depth' directories deep.")
	id_flags.BoolVarP(&include_meta, "metadata", "m", false, "Include filesystem metadata.")
	id_flags.StringVarP(&formatting_string, "formatting", "f", "id", "Output formatting options.\n          \"id\": c4id oriented.\n          \"path\": path oriented.")

	// cp
	cp_flags.BoolVarP(&archive_cp_flag, "archive", "a", false, "Same as -pPR options.")
	cp_flags.BoolVarP(&force_cp_flag, "force", "f", false, "Force.")
	cp_flags.BoolVarP(&follow_all_links_cp_flag, "follow_all_links", "H", false, "Follow all symbolic links.")
	cp_flags.BoolVarP(&prompt_cp_flag, "prompt", "i", false, "Prompt before overwriting an existing file.")
	cp_flags.BoolVarP(&follow_links_cp_flag, "follow_links", "L", false, "Follow links instead of copy with -R option.")
	cp_flags.BoolVarP(&noclobber_cp_flag, "noclobber", "n", false, "Do not overwrite existing files.")
	cp_flags.BoolVarP(&copy_links_cp_flag, "copy_links", "P", true, "Copy links with -R option (default).")
	cp_flags.BoolVarP(&preserve_cp_flag, "preserve", "p", false, "Preserve attributes.")
	cp_flags.BoolVarP(&recursive_cp_flag, "recursive", "R", false, "Copy recursively.")
	cp_flags.BoolVarP(&verbose_cp_flag, "verbose", "v", false, "Verbose output.")
	cp_flags.VarP(&target_cp_flag, "target", "T", "Specify additional target paths, can be used more than once.")
}
Ejemplo n.º 2
0
func NewCmd(l log15.Logger, server *Server, version string) *Cmd {
	var (
		flags = &flags{
			FlagSet: pflag.NewFlagSet("", pflag.ExitOnError),
		}
	)

	flags.Usage = func() {
		fmt.Fprintf(os.Stderr, "Usage:\n")
		flags.PrintDefaults()
	}

	flags.StringVar(&flags.location, "location", "", "unix socket for http")
	flags.StringVar(&flags.statedir, "statedir", "", "statedir location")
	flags.BoolVarP(&flags.help, "help", "h", false, "show help")
	flags.BoolVarP(&flags.version, "version", "v", false, "show version")
	flags.BoolVar(&flags.verbose, "verbose", false, "verbose output")

	return &Cmd{
		Logger:  l,
		flags:   flags,
		Server:  server,
		version: version,
	}
}
Ejemplo n.º 3
0
func (cmd *Download) parseFlags() (exitCode int, err error) {

	var showUsage bool

	fs := flag.NewFlagSet("conoha-ojs-download", flag.ContinueOnError)
	fs.BoolVarP(&showUsage, "help", "h", false, "Print usage.")

	err = fs.Parse(os.Args[2:])
	if err != nil {
		return ExitCodeParseFlagError, err
	}

	if showUsage {
		return ExitCodeUsage, nil
	}

	if len(os.Args) < 3 {
		return ExitCodeParseFlagError, errors.New("Not enough arguments.")
	}

	// 取得するオブジェクト名
	cmd.objectName = os.Args[2]

	// 保存先のパス
	if len(os.Args) == 4 {
		cmd.destPath = os.Args[3]

	} else {
		cmd.destPath = "."
	}

	return ExitCodeOK, nil
}
Ejemplo n.º 4
0
Archivo: cli.go Proyecto: pocke/to-gist
func FlagParse(args []string) (*CLI, error) {
	fs := pflag.NewFlagSet(args[0], pflag.ContinueOnError)

	cli := &CLI{}

	fs.BoolVarP(&cli.Public, "private", "p", false, "make private")

	err := fs.Parse(args[1:])
	if err != nil {
		return nil, err
	}
	cli.Public = !cli.Public

	if len(fs.Args()) != 1 {
		return nil, fmt.Errorf("file name is required")
	}
	cli.FileName = fs.Arg(0)

	content, err := ioutil.ReadAll(os.Stdin)
	if err != nil {
		return nil, err
	}
	cli.FileContent = string(content)

	return cli, nil
}
Ejemplo n.º 5
0
// コマンドライン引数を処理して、一覧表示するコンテナ名を返す
// 引数が省略された場合はルートを決め打ちする
func (cmd *List) parseFlags() (exitCode int, err error) {

	var showUsage bool
	fs := flag.NewFlagSet("conoha-ojs-list", flag.ContinueOnError)
	fs.BoolVarP(&showUsage, "help", "h", false, "Print usage.")

	err = fs.Parse(os.Args[2:])
	if err != nil {
		return ExitCodeParseFlagError, err
	}

	if showUsage {
		return ExitCodeUsage, nil
	}

	if len(os.Args) == 2 {
		// コンテナ名が指定されなかったときはルートを決め打ちする
		cmd.containerName = "/"

	} else if len(os.Args) < 2 {
		return ExitCodeParseFlagError, errors.New("Not enough arguments.")

	} else {
		cmd.containerName = os.Args[2]
	}

	return ExitCodeOK, nil
}
Ejemplo n.º 6
0
func (cmd *Delete) parseFlags() (exitCode int, err error) {

	var showUsage bool

	fs := flag.NewFlagSet("conoha-ojs-delete", flag.ContinueOnError)
	fs.BoolVarP(&showUsage, "help", "h", false, "Print usage.")

	err = fs.Parse(os.Args[2:])
	if err != nil {
		return ExitCodeParseFlagError, err
	}

	if showUsage {
		return ExitCodeUsage, nil
	}

	if fs.NArg() < 1 {
		return ExitCodeParseFlagError, errors.New("Not enough arguments.")
	}

	// 削除するオブジェクト名
	cmd.objectName = os.Args[2]

	return ExitCodeOK, nil
}
Ejemplo n.º 7
0
// 引数-mでメタデータを指定する
// メタデータはコロン区切りの key:value の形式で渡す。
func (cmd *Post) parseFlags() (exitCode int, err error) {

	// 初期化
	cmd.metadatas = strmap{}

	var showUsage bool

	fs := flag.NewFlagSet("conoha-ojs-post", flag.ContinueOnError)

	fs.BoolVarP(&showUsage, "help", "h", false, "Print usage.")
	fs.VarP(&cmd.metadatas, "meta", "m", "Key and value of metadata.")
	fs.StringVarP(&cmd.readAcl, "read-acl", "r", "_no_assign_", "Read ACL for containers.")
	fs.StringVarP(&cmd.writeAcl, "write-acl", "w", "_no_assign_", "Write ACL for containers.")

	err = fs.Parse(os.Args[2:])
	if err != nil {
		return ExitCodeParseFlagError, err
	}

	if showUsage {
		return ExitCodeUsage, nil
	}

	// メタデータを操作するオブジェクト
	cmd.objectName = fs.Arg(0)
	if cmd.objectName == "" {
		return ExitCodeParseFlagError, errors.New("Not enough arguments.")
	}

	return ExitCodeOK, nil
}
Ejemplo n.º 8
0
func readConfigsFromReader(r io.Reader, name string) ([]*Config, error) {
	scanner := bufio.NewScanner(r)
	lineNo := 0
	var configs []*Config
	for scanner.Scan() {
		lineNo++
		errorf := fmt.Sprintf("error on line %d of %s: %%s", lineNo, name)
		c := &Config{}
		flags := flag.NewFlagSet("", flag.ContinueOnError)
		flags.SetOutput(ioutil.Discard)
		c.registerFlags(flags)
		parts, err := shellquote.Split(scanner.Text())
		if err != nil {
			return nil, fmt.Errorf(errorf, err)
		}
		// Skip empty lines and comments (lines starting with #).
		if len(parts) == 0 || strings.HasPrefix(parts[0], "#") {
			continue
		}
		if err := flags.Parse(parts); err != nil {
			return nil, fmt.Errorf(errorf, err)
		}
		c.command = flags.Args()
		c.source = fmt.Sprintf("%s, line %d", name, lineNo)
		configs = append(configs, c)
	}
	if err := scanner.Err(); err != nil {
		return nil, fmt.Errorf("error reading config from %s: %s", name, err)
	}
	return configs, nil
}
Ejemplo n.º 9
0
// Read configuration from both profile and flags. Flags override profile.
func config() (*flag.FlagSet, error) {
	dir, err := getCfgDir(".boot2docker")
	if err != nil {
		return nil, fmt.Errorf("failed to get boot2docker directory: %s", err)
	}

	flags := flag.NewFlagSet(os.Args[0], flag.ContinueOnError)
	flags.Usage = func() { usageLong(flags) }

	flags.StringVar(&B2D.VM, "vm", "boot2docker-vm", "virtual machine name.")
	flags.StringVarP(&B2D.Dir, "dir", "d", dir, "boot2docker config directory.")
	flags.StringVar(&B2D.ISO, "iso", filepath.Join(dir, "boot2docker.iso"), "path to boot2docker ISO image.")
	flags.StringVar(&B2D.VMDK, "basevmdk", "", "Path to VMDK to use as base for persistent partition")
	vbm := "VBoxManage"
	if p := os.Getenv("VBOX_INSTALL_PATH"); p != "" && runtime.GOOS == "windows" {
		vbm = filepath.Join(p, "VBoxManage.exe")
	}
	flags.StringVar(&B2D.VBM, "vbm", vbm, "path to VirtualBox management utility.")
	flags.BoolVarP(&B2D.Verbose, "verbose", "v", false, "display verbose command invocations.")
	flags.StringVar(&B2D.SSH, "ssh", "ssh", "path to SSH client utility.")
	flags.StringVar(&B2D.SSHGen, "ssh-keygen", "ssh-keygen", "path to ssh-keygen utility.")

	sshdir, _ := getCfgDir(".ssh")
	flags.StringVar(&B2D.SSHKey, "sshkey", filepath.Join(sshdir, "id_boot2docker"), "path to SSH key to use.")
	flags.UintVarP(&B2D.DiskSize, "disksize", "s", 20000, "boot2docker disk image size (in MB).")
	flags.UintVarP(&B2D.Memory, "memory", "m", 1024, "virtual machine memory size (in MB).")
	flags.Uint16Var(&B2D.SSHPort, "sshport", 2022, "host SSH port (forward to port 22 in VM).")
	flags.Uint16Var(&B2D.DockerPort, "dockerport", 4243, "host Docker port (forward to port 4243 in VM).")
	flags.IPVar(&B2D.HostIP, "hostip", net.ParseIP("192.168.59.3"), "VirtualBox host-only network IP address.")
	flags.IPMaskVar(&B2D.NetMask, "netmask", flag.ParseIPv4Mask("255.255.255.0"), "VirtualBox host-only network mask.")
	flags.BoolVar(&B2D.DHCPEnabled, "dhcp", true, "enable VirtualBox host-only network DHCP.")
	flags.IPVar(&B2D.DHCPIP, "dhcpip", net.ParseIP("192.168.59.99"), "VirtualBox host-only network DHCP server address.")
	flags.IPVar(&B2D.LowerIP, "lowerip", net.ParseIP("192.168.59.103"), "VirtualBox host-only network DHCP lower bound.")
	flags.IPVar(&B2D.UpperIP, "upperip", net.ParseIP("192.168.59.254"), "VirtualBox host-only network DHCP upper bound.")

	// Set the defaults
	if err := flags.Parse([]string{}); err != nil {
		return nil, err
	}
	// Over-ride from the profile file
	// TODO: should we really parse for and expand $ENVVARS before we process..?
	filename := getCfgFilename(dir)
	if _, err := toml.DecodeFile(filename, &B2D); err != nil {
		return nil, err
	}
	// Command-line overrides profile config.
	if err := flags.Parse(os.Args[1:]); err != nil {
		return nil, err
	}

	// Name of VM is the second argument. Override the value set in flag.
	if vm := flags.Arg(1); vm != "" {
		B2D.VM = vm
	}

	vbx.Verbose = B2D.Verbose
	vbx.VBM = B2D.VBM
	return flags, nil
}
Ejemplo n.º 10
0
func parseCommandLine(cmdLine []string) (Args, error) {
	var result Args
	flags := pflag.NewFlagSet("Sarge", pflag.ContinueOnError)
	flags.StringVarP(&result.ImageFile, "image", "i", "",
		"The image file to load")
	err := flags.Parse(cmdLine)
	return result, err
}
Ejemplo n.º 11
0
func parseFlags(args []string) (*config.Config, error) {
	var doHelp bool
	var doVersion bool
	var c = config.DefaultConfig()

	flags := flag.NewFlagSet("mesos-consul", flag.ContinueOnError)
	flags.Usage = func() {
		fmt.Println(Help())
	}

	flags.BoolVar(&doHelp, "help", false, "")
	flags.BoolVar(&doVersion, "version", false, "")
	flags.StringVar(&c.LogLevel, "log-level", "WARN", "")
	flags.DurationVar(&c.Refresh, "refresh", time.Minute, "")
	flags.StringVar(&c.Zk, "zk", "zk://127.0.0.1:2181/mesos", "")
	flags.StringVar(&c.MesosIpOrder, "mesos-ip-order", "netinfo,mesos,host", "")
	flags.BoolVar(&c.Healthcheck, "healthcheck", false, "")
	flags.StringVar(&c.HealthcheckIp, "healthcheck-ip", "127.0.0.1", "")
	flags.StringVar(&c.HealthcheckPort, "healthcheck-port", "24476", "")
	flags.Var((funcVar)(func(s string) error {
		c.WhiteList = append(c.WhiteList, s)
		return nil
	}), "whitelist", "")
	flags.StringVar(&c.ServiceName, "service-name", "mesos", "")
	flags.StringVar(&c.ServiceTags, "service-tags", "", "")

	consul.AddCmdFlags(flags)

	if err := flags.Parse(args); err != nil {
		return nil, err
	}

	args = flags.Args()
	if len(args) > 0 {
		return nil, fmt.Errorf("extra argument(s): %q", args)
	}

	if doVersion {
		fmt.Printf("%s v%s\n", Name, Version)
		os.Exit(0)
	}
	if doHelp {
		flags.Usage()
		os.Exit(0)
	}

	l, err := log.ParseLevel(strings.ToLower(c.LogLevel))
	if err != nil {
		log.SetLevel(log.WarnLevel)
		log.Warnf("Invalid log level '%v'. Setting to WARN", c.LogLevel)
	} else {
		log.SetLevel(l)
	}

	return c, nil
}
Ejemplo n.º 12
0
Archivo: cli.go Proyecto: tcsc/squaddie
// ParseCommandLine parses the standard command line interface for a squaddie
// plugin
func ParseCommandLine(cmdLine []string) (Args, error) {
	var result Args
	flags := pflag.NewFlagSet("Plugin API", pflag.ContinueOnError)
	flags.StringVarP(&result.Network, "network", "n", "unix",
		"The network type")
	flags.StringVarP(&result.Path, "path", "p", "/var/sarge.sock",
		"The RPC endpoint")

	err := flags.Parse(cmdLine)
	return result, err
}
Ejemplo n.º 13
0
func (c *CLI) Parse(args []string) error {
	cmds := make(Commands, 0)
	c.Commands = cmds

	fset := pflag.NewFlagSet(args[0], pflag.ContinueOnError)
	fset.VarP(&c.Commands, "command", "c", "command")

	err := fset.Parse(args[1:])
	c.Files = fset.Args()
	return err
}
Ejemplo n.º 14
0
func RunServer(args []string) {
	flags := flag.NewFlagSet("server", flag.ExitOnError)
	addCommonOptions(flags)
	flags.Parse(args)

	// We start the transports in another goroutine, so our main routine can
	// return (and wait for signals).
	// Note: The startTransports function takes ownership (and closes) the
	// tuntap device.
	tt := getTuntap(false)
	go startTransports(tt)
}
Ejemplo n.º 15
0
func httpHandle(args []string) {
	set := pflag.NewFlagSet("http", pflag.ExitOnError)
	addr := set.StringP("addr", "a", ":8080", "Listen address.")
	set.Parse(args)

	if addr == nil {
		set.Usage()
		os.Exit(1)
	}

	if err := ListenAndServe(*addr); err != nil {
		log.Fatal(err)
	}
}
Ejemplo n.º 16
0
func NewFlagSet(c *ConsulFlags) *flag.FlagSet {
	consulFlags := flag.NewFlagSet("consulacl", flag.ContinueOnError)
	consulFlags.StringVar(&c.consulAddr, "consul", "127.0.0.1:8500", "")
	consulFlags.BoolVar(&c.sslEnabled, "ssl", false, "")
	consulFlags.BoolVar(&c.sslVerify, "ssl-verify", true, "")
	consulFlags.StringVar(&c.sslCert, "ssl-cert", "", "")
	consulFlags.StringVar(&c.sslCaCert, "ssl-ca-cert", "", "")
	consulFlags.StringVar(&c.token, "token", "", "")

	c.auth = new(Auth)
	consulFlags.Var((*Auth)(c.auth), "auth", "")

	return consulFlags
}
Ejemplo n.º 17
0
func parseFlags(args []string) (*config.Config, error) {
	var doHelp bool
	var c = config.DefaultConfig()

	flags := flag.NewFlagSet("mesos-consul", flag.ContinueOnError)
	flags.Usage = func() {
		fmt.Println(Help())
	}

	flags.BoolVar(&doHelp, "help", false, "")
	flags.StringVar(&c.LogLevel, "log-level", "WARN", "")
	flags.DurationVar(&c.Refresh, "refresh", time.Minute, "")
	flags.StringVar(&c.RegistryPort, "registry-port", "8500", "")
	flags.Var((*config.AuthVar)(c.RegistryAuth), "registry-auth", "")
	flags.BoolVar(&c.RegistrySSL.Enabled, "registry-ssl", c.RegistrySSL.Enabled, "")
	flags.BoolVar(&c.RegistrySSL.Verify, "registry-ssl-verify", c.RegistrySSL.Verify, "")
	flags.StringVar(&c.RegistrySSL.Cert, "registry-ssl-cert", c.RegistrySSL.Cert, "")
	flags.StringVar(&c.RegistrySSL.CaCert, "registry-ssl-cacert", c.RegistrySSL.CaCert, "")
	flags.StringVar(&c.RegistryToken, "registry-token", c.RegistryToken, "")
	flags.StringVar(&c.Zk, "zk", "zk://127.0.0.1:2181/mesos", "")

	consul.AddCmdFlags(flags)

	if err := flags.Parse(args); err != nil {
		return nil, err
	}

	args = flags.Args()
	if len(args) > 0 {
		return nil, fmt.Errorf("extra argument(s): %q", args)
	}

	if doHelp {
		flags.Usage()
		os.Exit(0)
	}

	l, err := log.ParseLevel(c.LogLevel)
	if err != nil {
		log.SetLevel(log.WarnLevel)
		log.Warnf("Invalid log level '%v'. Setting to WARN")
	} else {
		log.SetLevel(l)
	}

	return c, nil
}
Ejemplo n.º 18
0
func optionsSet() *pflag.FlagSet {
	set := pflag.NewFlagSet("options", pflag.ExitOnError)

	defaultMBox, _ := mailbox.DefaultMailboxPath()

	set.StringVar(&fOptions.MyCall, `mycall`, ``, `Your callsign (winlink user).`)
	set.StringVarP(&fOptions.Listen, "listen", "l", "", "Comma-separated list of methods to listen on (e.g. winmor,ardop,telnet,ax25).")
	set.StringVar(&fOptions.MailboxPath, "mbox", defaultMBox, "Path to mailbox directory")
	set.StringVar(&fOptions.ConfigPath, "config", fOptions.ConfigPath, "Path to config file")
	set.StringVar(&fOptions.LogPath, "log", fOptions.LogPath, "Path to log file. The file is truncated on each startup.")
	set.StringVar(&fOptions.EventLogPath, "event-log", fOptions.EventLogPath, "Path to event log file.")
	set.BoolVarP(&fOptions.SendOnly, `send-only`, "s", false, `Download inbound messages later, send only.`)
	set.BoolVarP(&fOptions.RobustWinmor, `robust-winmor`, "r", false, `Use robust winmor modes only. (Usefull to improve s/n-ratio at remote station.)`)
	set.BoolVar(&fOptions.IgnoreBusy, "ignore-busy", false, "Don't wait for clear channel before connecting to a node.")

	return set
}
Ejemplo n.º 19
0
func parseFlags(args []string) (*config.Config, error) {
	var doHelp bool
	var c = config.DefaultConfig()

	flags := flag.NewFlagSet("mesos-consul", flag.ContinueOnError)
	flags.Usage = func() {
		fmt.Print(usage)
	}

	flags.BoolVar(&doHelp, "help", false, "")
	flags.StringVar(&c.LogLevel, "log-level", "WARN", "")
	flags.DurationVar(&c.Refresh, "refresh", time.Minute, "")
	flags.StringVar(&c.RegistryPort, "registry-port", "8500", "")
	flags.Var((*config.AuthVar)(c.RegistryAuth), "registry-auth", "")
	flags.BoolVar(&c.RegistrySSL.Enabled, "registry-ssl", c.RegistrySSL.Enabled, "")
	flags.BoolVar(&c.RegistrySSL.Verify, "registry-ssl-verify", c.RegistrySSL.Verify, "")
	flags.StringVar(&c.RegistrySSL.Cert, "registry-ssl-cert", c.RegistrySSL.Cert, "")
	flags.StringVar(&c.RegistrySSL.CaCert, "registry-ssl-cacert", c.RegistrySSL.CaCert, "")
	flags.StringVar(&c.RegistryToken, "registry-token", c.RegistryToken, "")
	flags.StringVar(&c.Zk, "zk", "zk://127.0.0.1:2181/mesos", "")

	if err := flags.Parse(args); err != nil {
		return nil, err
	}

	args = flags.Args()
	if len(args) > 0 {
		return nil, fmt.Errorf("extra argument(s): %q", args)
	}

	if doHelp {
		flags.Usage()
		os.Exit(0)
	}

	logging.Setup(&logging.Config{
		Name:   "mesos-consul",
		Level:  c.LogLevel,
		Writer: os.Stderr,
	})

	return c, nil
}
Ejemplo n.º 20
0
Archivo: main.go Proyecto: pocke/letter
func ParseFlag(args []string) ([]string, Commands, error) {
	fset := pflag.NewFlagSet(args[0], pflag.ExitOnError)
	globs := make(Strings, 0)
	commands := make(Commands, 0)
	fset.VarP(&globs, "glob", "g", "glob")
	fset.VarP(&commands, "command", "c", "command")
	fset.BoolVarP(&logger.debug, "debug", "d", false, "enable debug")

	conf, err := LoadConfig()
	if err != nil {
		return nil, nil, err
	}
	a := append(conf, args[1:]...)
	if err := fset.Parse(a); err != nil {
		return nil, nil, err
	}

	return globs, commands, nil
}
Ejemplo n.º 21
0
func (m *Meta) FlagSet() *flag.FlagSet {
	f := flag.NewFlagSet("consul-cli", flag.ContinueOnError)
	f.StringVar(&m.consulAddr, "consul", "", "")
	f.BoolVar(&m.sslEnabled, "ssl", false, "")
	f.BoolVar(&m.sslVerify, "ssl-verify", true, "")
	f.StringVar(&m.sslCert, "ssl-cert", "", "")
	f.StringVar(&m.sslCaCert, "ssl-ca-cert", "", "")
	f.StringVar(&m.token, "token", "", "")
	if m.hasDc {
		f.StringVar(&m.dc, "datacenter", "", "")
	}
	if m.hasWait {
		f.Uint64Var(&m.waitIndex, "wait-index", 0, "")
	}

	m.auth = new(Auth)
	f.Var((*Auth)(m.auth), "auth", "")

	return f
}
Ejemplo n.º 22
0
func (cmd *Upload) parseFlags() (exitCode int, err error) {

	var showUsage bool

	fs := flag.NewFlagSet("conoha-ojs-upload", flag.ContinueOnError)

	// コマンドライン引数の定義を追加
	fs.BoolVarP(&showUsage, "help", "h", false, "Print usage.")
	fs.StringVarP(&cmd.contentType, "content-type", "c", "", "Set Content-type")

	err = fs.Parse(os.Args[2:])
	if err != nil {
		return ExitCodeParseFlagError, err
	}

	if showUsage {
		return ExitCodeUsage, nil
	}

	if fs.NArg() < 2 {
		return ExitCodeParseFlagError, errors.New("Not enough arguments.")
	}

	// アップロード先コンテナ
	cmd.destContainer = fs.Arg(0)

	// アップロードするファイル
	for i := 1; i < fs.NArg(); i++ {
		filename := fs.Arg(i)

		_, err := os.Stat(filename)
		if err != nil {
			msg := fmt.Sprintf("File \"%s\" not found.", filename)
			return ExitCodeError, errors.New(msg)
		}

		cmd.srcFiles = append(cmd.srcFiles, filename)
	}

	return ExitCodeOK, nil
}
Ejemplo n.º 23
0
func parseFlags(args []string) (*config.Config, error) {
	var doHelp bool
	var c = config.DefaultConfig()

	flags := flag.NewFlagSet("mesos-consul", flag.ContinueOnError)
	flags.Usage = func() {
		fmt.Println(Help())
	}

	flags.BoolVar(&doHelp, "help", false, "")
	flags.StringVar(&c.LogLevel, "log-level", "WARN", "")
	flags.DurationVar(&c.Refresh, "refresh", time.Minute, "")
	flags.StringVar(&c.Zk, "zk", "zk://127.0.0.1:2181/mesos", "")
	flags.StringVar(&c.MesosIpOrder, "mesos-ip-order", "netinfo,mesos,host", "")

	consul.AddCmdFlags(flags)

	if err := flags.Parse(args); err != nil {
		return nil, err
	}

	args = flags.Args()
	if len(args) > 0 {
		return nil, fmt.Errorf("extra argument(s): %q", args)
	}

	if doHelp {
		flags.Usage()
		os.Exit(0)
	}

	l, err := log.ParseLevel(strings.ToLower(c.LogLevel))
	if err != nil {
		log.SetLevel(log.WarnLevel)
		log.Warnf("Invalid log level '%v'. Setting to WARN", c.LogLevel)
	} else {
		log.SetLevel(l)
	}

	return c, nil
}
Ejemplo n.º 24
0
func RunClient(args []string) {
	flags := flag.NewFlagSet("client", flag.ExitOnError)
	addCommonOptions(flags)

	flags.StringVar(&method, "m", "all", "methods to try, as comma-seperated list (tcp/udp/icmp/dns/all)")
	flags.StringVar(&server_addr, "server", "10.93.0.1", "ip address of the server")

	flags.Parse(args)

	cmd_args := flags.Args()
	if len(cmd_args) < 1 {
		fmt.Fprintf(os.Stderr, "No server address given!\n\n")
		fmt.Fprintf(os.Stderr, "Usage:\n")
		fmt.Fprintf(os.Stderr, "  holepunch client [options] server_addr\n\n")
		os.Exit(1)
	} else {
		// Use a different goroutine, so the main routine can wait for signals.
		tt := getTuntap(true)
		go startClient(tt, cmd_args[0])
	}
}
Ejemplo n.º 25
0
Archivo: main.go Proyecto: tcsc/impact
func parseArgs() (arguments, error) {
	var result arguments

	flags := pflag.NewFlagSet("Impact", pflag.ContinueOnError)
	flags.StringVarP(&result.packageName, "package", "p", "",
		"The package to test. Paths in the patch file must be relative to this.")
	flags.StringVarP(&result.packageListFile, "package-file", "f", "packages.txt",
		"The file containing the list of packages to test")
	flags.StringVarP(&result.patchFile, "delta", "d", "delta.patch",
		"A patch describing the change to test")
	flags.DurationVarP(&result.fetchTimeout, "timeout", "t", 60*time.Minute,
		"How long to wait for the source code fetch befor giving up.")
	flags.StringVarP(&result.reportFile, "report", "r", "report.txt",
		"How long to wait for the source code frtch befor giving up.")
	flags.IntVarP(&result.concurrency, "concurrency", "n", 8,
		"How many tests to run simultaneously")

	err := flags.Parse(os.Args[1:])
	if err != nil {
		return result, err
	}

	if result.packageName == "" {
		return result, errors.New("Must specify a package to test")
	}

	result.packageListFile, err = filepath.Abs(result.packageListFile)
	if err != nil {
		return result, err
	}

	result.patchFile, err = filepath.Abs(result.patchFile)
	if err != nil {
		return result, err
	}

	result.reportFile, err = filepath.Abs(result.reportFile)

	return result, err
}
Ejemplo n.º 26
0
func (cmd *Stat) parseFlags() (exitCode int, err error) {
	var showUsage bool

	fs := flag.NewFlagSet("conoha-ojs-post", flag.ContinueOnError)

	fs.BoolVarP(&showUsage, "help", "h", false, "Print usage.")

	err = fs.Parse(os.Args[2:])
	if err != nil {
		return ExitCodeParseFlagError, err
	}

	if showUsage {
		return ExitCodeUsage, nil
	}

	cmd.objectName = fs.Arg(0)
	if cmd.objectName == "" {
		// オブジェクトが指定されなかった場合、一番上位のコンテナが指定されるのでそのまま進めて良い
	}
	return ExitCodeOK, nil
}
Ejemplo n.º 27
0
// コマンドライン引数を処理して返す
func (cmd *Auth) parseFlags() (exitCode int, err error) {

	var showUsage bool
	fs := flag.NewFlagSet("conoha-ojs-auth", flag.ContinueOnError)

	// コマンドライン引数の定義を追加
	fs.BoolVarP(&showUsage, "help", "h", false, "Print usage.")
	fs.StringVarP(&cmd.username, "api-username", "u", "", "API Username")
	fs.StringVarP(&cmd.password, "api-password", "p", "", "API Password")
	fs.StringVarP(&cmd.authUrl, "auth-url", "a", "", "Auth URL")
	fs.StringVarP(&cmd.tenantId, "tenant-id", "t", "", "Tenant ID")

	err = fs.Parse(os.Args[2:])
	if err != nil {
		return ExitCodeParseFlagError, err
	}

	if showUsage {
		return ExitCodeUsage, nil
	}

	// ユーザ名、パスワードを未指定の場合はUsageを表示して終了
	if cmd.username == "" || cmd.password == "" || cmd.tenantId == "" {
		return ExitCodeParseFlagError, errors.New("Not enough arguments.")
	}

	// 認証URLの指定がない場合はデフォルトを使用
	if cmd.authUrl == "" {
		cmd.authUrl = DEFAULT_AUTH_URL
	}

	// 末尾のURLを削除する
	if strings.HasSuffix(cmd.authUrl, "/") {
		cmd.authUrl = cmd.authUrl[0 : len(cmd.authUrl)-1]
	}

	return ExitCodeOK, nil
}
Ejemplo n.º 28
0
func rmsListHandle(args []string) {
	set := pflag.NewFlagSet("rmslist", pflag.ExitOnError)
	mode := set.StringP("mode", "m", "", "")
	forceDownload := set.BoolP("force-download", "d", false, "")
	set.Parse(args)

	appDir, err := mailbox.DefaultAppDir()
	if err != nil {
		log.Fatal(err)
	}
	filePath := path.Join(appDir, "rmslist.json") // Should be moved to a tmp-folder, along with logfile.

	var query string
	if len(set.Args()) > 0 {
		query = strings.ToUpper(set.Args()[0])
	}

	file, err := GetGatewayStatusCached(filePath, *forceDownload)
	if err != nil {
		log.Fatal(err)
	}
	defer file.Close()

	var status GatewayStatus

	err = json.NewDecoder(file).Decode(&status)
	if err != nil {
		log.Fatal(err)
	}

	*mode = strings.ToLower(*mode)

	fmtStr := "%-9.9s [%-6.6s] %-15.15s %14.14s %14.14s\n"

	// Print header
	fmt.Printf(fmtStr, "callsign", "gridsq", "mode(s)", "dial freq", "center freq") //TODO: "center frequency" of packet is wrong...

	// Print gateways (separated by blank line)
	for _, gw := range status.Gateways {
		switch {
		case query != "" && !strings.HasPrefix(gw.Callsign, query):
			continue
		default:
		}

		var printed bool
		for _, channel := range gw.Channels {
			if mode != nil && !strings.Contains(strings.ToLower(channel.SupportedModes), *mode) {
				continue
			}
			printed = true

			freq := Frequency(channel.Frequency)
			dial := freq.Dial(channel.SupportedModes)
			fmt.Printf(fmtStr, gw.Callsign, channel.Gridsquare, channel.SupportedModes, dial, freq)
		}
		if printed {
			fmt.Println("")
		}
	}
}
Ejemplo n.º 29
0
	flag "github.com/ogier/pflag"
	"gopkg.in/fsnotify.v1"
)

const defaultSubSymbol = "{}"

var (
	reflexes []*Reflex

	flagConf       string
	flagSequential bool
	flagDecoration string
	decoration     Decoration
	verbose        bool
	globalFlags    = flag.NewFlagSet("", flag.ContinueOnError)
	globalConfig   = &Config{}

	reflexID = 0
	stdout   = make(chan OutMsg, 1)

	cleanupMu = &sync.Mutex{}
)

func usage() {
	fmt.Fprintf(os.Stderr, `Usage: %s [OPTIONS] [COMMAND]

COMMAND is any command you'd like to run. Any instance of {} will be replaced
with the filename of the changed file. (The symbol may be changed with the
--substitute flag.)
Ejemplo n.º 30
0
// Read configuration from both profile and flags. Flags override profile.
func config() (*flag.FlagSet, error) {
	dir, err := getCfgDir(".boot2kevoree")
	if err != nil {
		return nil, fmt.Errorf("failed to get boot2kevoree directory: %s", err)
	}

	flags := flag.NewFlagSet(os.Args[0], flag.ContinueOnError)
	flags.Usage = func() { usageLong(flags) }

	flags.StringVar(&B2D.VM, "vm", "boot2kevoree-vm", "virtual machine name.")
	// removed for now, requires re-parsing a new config file which is too messy
	//flags.StringVarP(&B2D.Dir, "dir", "d", dir, "boot2kevoree config directory.")
	B2D.Dir = dir
	flags.StringVar(&B2D.ISO, "iso", filepath.Join(dir, "boot2kevoree.iso"), "path to boot2kevoree ISO image.")
	flags.StringVar(&B2D.VMDK, "basevmdk", "", "Path to VMDK to use as base for persistent partition")
	vbm := "VBoxManage"
	if p := os.Getenv("VBOX_INSTALL_PATH"); p != "" && runtime.GOOS == "windows" {
		vbm = filepath.Join(p, "VBoxManage.exe")
	}
	flags.StringVar(&B2D.VBM, "vbm", vbm, "path to VirtualBox management utility.")
	flags.BoolVarP(&B2D.Verbose, "verbose", "v", false, "display verbose command invocations.")
	flags.StringVar(&B2D.SSH, "ssh", "ssh", "path to SSH client utility.")
	flags.StringVar(&B2D.SSHGen, "ssh-keygen", "ssh-keygen", "path to ssh-keygen utility.")

	sshdir, _ := getCfgDir(".ssh")
	flags.StringVar(&B2D.SSHKey, "sshkey", filepath.Join(sshdir, "id_boot2kevoree"), "path to SSH key to use.")
	flags.UintVarP(&B2D.DiskSize, "disksize", "s", 20000, "boot2kevoree disk image size (in MB).")
	flags.UintVarP(&B2D.Memory, "memory", "m", 1024, "virtual machine memory size (in MB).")
	flags.Uint16Var(&B2D.SSHPort, "sshport", 2022, "host SSH port (forward to port 22 in VM).")
	flags.Uint16Var(&B2D.DockerPort, "dockerport", 4243, "host Docker port (forward to port 4243 in VM).")
	flags.Uint16Var(&B2D.WebGuiPort, "kevguiport", 8080, "host KevoreeGui port (forward to port 8080 in VM).")
	flags.Uint16Var(&B2D.GroupPort, "kevgroup", 9000, "host KevoreeGroup port (forward to port 9000 in VM).")
	flags.Uint16Var(&B2D.EditorPort, "keveditorport", 3042, "host Kevoree Editor port (forward to port 3042 in VM).")

	flags.IPVar(&B2D.HostIP, "hostip", net.ParseIP("192.168.59.3"), "VirtualBox host-only network IP address.")
	flags.IPMaskVar(&B2D.NetMask, "netmask", flag.ParseIPv4Mask("255.255.255.0"), "VirtualBox host-only network mask.")
	flags.BoolVar(&B2D.DHCPEnabled, "dhcp", true, "enable VirtualBox host-only network DHCP.")
	flags.IPVar(&B2D.DHCPIP, "dhcpip", net.ParseIP("192.168.59.99"), "VirtualBox host-only network DHCP server address.")
	flags.IPVar(&B2D.LowerIP, "lowerip", net.ParseIP("192.168.59.103"), "VirtualBox host-only network DHCP lower bound.")
	flags.IPVar(&B2D.UpperIP, "upperip", net.ParseIP("192.168.59.254"), "VirtualBox host-only network DHCP upper bound.")

	// Set the defaults
	if err := flags.Parse([]string{}); err != nil {
		return nil, err
	}
	// Over-ride from the profile file
	filename := getCfgFilename(B2D.Dir)
	if _, err := os.Lstat(filename); err == nil {
		if _, err := toml.DecodeFile(filename, &B2D); err != nil {
			return nil, err
		}
	}

	// for cmd==ssh only:
	// only pass the params up to and including the `ssh` command - after that,
	// there might be other -flags that are destined for the ssh cmd
	i := 1
	for i < len(os.Args) && os.Args[i-1] != "ssh" {
		i++
	}
	// Command-line overrides profile config.
	if err := flags.Parse(os.Args[1:i]); err != nil {
		return nil, err
	}

	vbx.Verbose = B2D.Verbose
	vbx.VBM = B2D.VBM
	return flags, nil
}