veyron/lib/flags: add flag groups.
Change-Id: Ia490369e153564b79d673feaee64d8e3c0e91564
diff --git a/lib/modules/core/echo.go b/lib/modules/core/echo.go
index 5fd3307..3f6ff42 100644
--- a/lib/modules/core/echo.go
+++ b/lib/modules/core/echo.go
@@ -38,11 +38,10 @@
}
func echoServer(stdin io.Reader, stdout, stderr io.Writer, env map[string]string, args ...string) error {
- fl, err := ParseCommonFlags(args)
+ fl, args, err := parseListenFlags(args)
if err != nil {
return fmt.Errorf("failed parsing args: %s", err)
}
- args = fl.Args()
if err := checkArgs(args, 2, "<message> <name>"); err != nil {
return err
}
@@ -68,14 +67,7 @@
}
func echoClient(stdin io.Reader, stdout, stderr io.Writer, env map[string]string, args ...string) error {
- fl, err := ParseCommonFlags(args)
- if err != nil {
- return fmt.Errorf("failed parsing args: %s", err)
- }
- args = fl.Args()
- if err := checkArgs(args, 2, "<name> <message>"); err != nil {
- return err
- }
+ args = args[1:]
name := args[0]
args = args[1:]
client := rt.R().Client()
diff --git a/lib/modules/core/mounttable.go b/lib/modules/core/mounttable.go
index 307dde3..9c4fec0 100644
--- a/lib/modules/core/mounttable.go
+++ b/lib/modules/core/mounttable.go
@@ -34,11 +34,11 @@
func runMT(root bool, stdin io.Reader, stdout, stderr io.Writer, env map[string]string, args ...string) error {
r := rt.R()
- fl, err := ParseCommonFlags(args)
+ fl, args, err := parseListenFlags(args)
if err != nil {
return fmt.Errorf("failed parsing args: %s", err)
}
- args = fl.Args()
+ // args = fl.Args()
lspec := initListenSpec(fl)
server, err := r.NewServer(options.ServesMountTable(true))
if err != nil {
diff --git a/lib/modules/core/proxy.go b/lib/modules/core/proxy.go
index 0e24fe1..7290543 100644
--- a/lib/modules/core/proxy.go
+++ b/lib/modules/core/proxy.go
@@ -18,11 +18,10 @@
}
func proxyServer(stdin io.Reader, stdout, stderr io.Writer, env map[string]string, args ...string) error {
- fl, err := ParseCommonFlags(args)
+ fl, args, err := parseListenFlags(args)
if err != nil {
return fmt.Errorf("failed parsing args: %s", err)
- }
- args = fl.Args()
+ } // args = fl.Args()
if err := checkArgs(args, -1, ""); err != nil {
return err
}
@@ -31,10 +30,10 @@
if err != nil {
return err
}
-
+ lf := fl.ListenFlags()
// TODO(ashankar): Set the second argument to r.Principal() once the
// old security model is no longer operational.
- proxy, err := proxy.New(rid, nil, fl.ListenProtocolFlag.String(), fl.ListenAddressFlag.String(), "")
+ proxy, err := proxy.New(rid, nil, lf.ListenProtocol.String(), lf.ListenAddress.String(), "")
if err != nil {
return err
}
diff --git a/lib/modules/core/util.go b/lib/modules/core/util.go
index 507b7e3..81b6101 100644
--- a/lib/modules/core/util.go
+++ b/lib/modules/core/util.go
@@ -9,23 +9,22 @@
"veyron.io/veyron/veyron/lib/flags"
)
-// ParseCommonFlags parses the supplied args for the common set of flags
-// and environment variables defined in in the veyron/lib/flags package.
-func ParseCommonFlags(args []string) (*flags.Flags, error) {
+func parseListenFlags(args []string) (*flags.Flags, []string, error) {
fs := flag.NewFlagSet("modules/core", flag.ContinueOnError)
- fl := flags.New(fs)
+ fl := flags.CreateAndRegister(fs, flags.Listen)
if len(args) == 0 {
- return fl, fmt.Errorf("no args supplied")
+ return fl, []string{}, nil
}
err := fl.Parse(args[1:])
- return fl, err
+ return fl, fl.Args(), err
}
func initListenSpec(fl *flags.Flags) ipc.ListenSpec {
+ lf := fl.ListenFlags()
return ipc.ListenSpec{
- Protocol: fl.ListenProtocolFlag.String(),
- Address: fl.ListenAddressFlag.String(),
- Proxy: fl.ListenProxyFlag,
+ Protocol: lf.ListenProtocol.String(),
+ Address: lf.ListenAddress.String(),
+ Proxy: lf.ListenProxy,
}
}