Exemple #1
0
func mainInner(g *libkb.GlobalContext) error {
	cl := libcmdline.NewCommandLine(true, client.GetExtraFlags())
	cl.AddCommands(client.GetCommands(cl, g))
	cl.AddCommands(service.GetCommands(cl, g))
	cl.AddHelpTopics(client.GetHelpTopics())

	var err error
	cmd, err = cl.Parse(os.Args)
	if err != nil {
		err = fmt.Errorf("Error parsing command line arguments: %s\n", err)
		return err
	}

	if cmd == nil {
		return nil
	}

	if !cl.IsService() {
		client.InitUI()
	}

	if err = g.ConfigureCommand(cl, cmd); err != nil {
		return err
	}
	g.StartupMessage()

	warnNonProd(g.Log, g.Env)

	if err = configureProcesses(g, cl, &cmd); err != nil {
		return err
	}

	return cmd.Run()
}
Exemple #2
0
// test that `keybase pgp help`, `keybase help pgp`, `keybase pgp` output the
// same thing.
func TestParentHelp(t *testing.T) {
	cl := libcmdline.NewCommandLine(true, GetExtraFlags())
	var buf1 bytes.Buffer
	cl.SetOutputWriter(&buf1)
	cl.AddCommands(GetCommands(cl, libkb.NewGlobalContextInit()))

	cmd, err := cl.Parse(strings.Fields("keybase pgp help"))
	if err != nil {
		t.Fatal(err)
	}
	if cmd != nil {
		t.Fatalf("expected nil command, got %T", cmd)
	}
	help1 := helpFilter(buf1)

	var buf2 bytes.Buffer
	cl.SetOutputWriter(&buf2)
	cmd, err = cl.Parse(strings.Fields("keybase help pgp"))
	if err != nil {
		t.Fatal(err)
	}
	if cmd != nil {
		t.Fatalf("expected nil command, got %T", cmd)
	}
	help2 := helpFilter(buf2)

	if help1 != help2 {
		t.Errorf("`keybase pgp help` and `keybase help pgp` output differed")
	}

	var buf3 bytes.Buffer
	cl.SetOutputWriter(&buf3)
	cmd, err = cl.Parse(strings.Fields("keybase pgp"))
	if err != nil {
		t.Fatal(err)
	}
	if cmd != nil {
		t.Fatalf("expected nil command, got %T", cmd)
	}
	help3 := helpFilter(buf3)

	if help1 != help3 {
		t.Errorf("`keybase pgp help` and `keybase pgp` output differed")
	}

	if help2 != help3 {
		t.Errorf("`keybase help pgp` and `keybase pgp` output differed")
	}

	t.Logf("keybase pgp help:\n%s\n\n", help1)
	t.Logf("keybase help pgp:\n%s\n\n", help2)
	t.Logf("keybase pgp:\n%s\n\n", help3)
}
Exemple #3
0
func TestHelp(t *testing.T) {
	cl := libcmdline.NewCommandLine(true, GetExtraFlags())
	var buf bytes.Buffer
	cl.SetOutputWriter(&buf)
	cl.AddCommands(GetCommands(cl, libkb.NewGlobalContextInit()))
	cmd, err := cl.Parse(strings.Fields("keybase pgp help"))
	if err != nil {
		t.Fatal(err)
	}
	if cmd != nil {
		t.Fatalf("expected nil command, got %T", cmd)
	}
}
Exemple #4
0
func mainInner(g *libkb.GlobalContext) error {
	cl := libcmdline.NewCommandLine(true, client.GetExtraFlags())
	cl.AddCommands(client.GetCommands(cl, g))
	cl.AddCommands(service.GetCommands(cl, g))
	cl.AddHelpTopics(client.GetHelpTopics())

	var err error
	cmd, err = cl.Parse(os.Args)
	if err != nil {
		err = fmt.Errorf("Error parsing command line arguments: %s\n", err)
		return err
	}

	if cmd == nil {
		return nil
	}

	checkSystemUser(g.Log)

	if !cl.IsService() {
		client.InitUI()
	}

	if err = g.ConfigureCommand(cl, cmd); err != nil {
		return err
	}
	g.StartupMessage()

	warnNonProd(g.Log, g.Env)

	if err = configureProcesses(g, cl, &cmd); err != nil {
		return err
	}

	// Install hook for after startup
	install.RunAfterStartup(g, cl.IsService(), g.Log)

	err = cmd.Run()
	if !cl.IsService() {
		// Errors that come up in printing this warning are logged but ignored.
		client.PrintOutOfDateWarnings(g)
	}
	return err
}
Exemple #5
0
func mainInner(g *libkb.GlobalContext) error {
	cl := libcmdline.NewCommandLine(true, client.GetExtraFlags())
	cl.AddCommands(client.GetCommands(cl, g))
	cl.AddCommands(service.GetCommands(cl, g))
	cl.AddHelpTopics(client.GetHelpTopics())

	var err error
	cmd, err = cl.Parse(os.Args)
	if err != nil {
		err = fmt.Errorf("Error parsing command line arguments: %s\n", err)
		return err
	}

	if cmd == nil {
		return nil
	}

	if !cl.IsService() {
		client.InitUI()
	}

	if err = g.ConfigureCommand(cl, cmd); err != nil {
		return err
	}
	g.StartupMessage()

	warnNonProd(g.Log, g.Env)

	if cl.IsService() {
		return cmd.Run()
	}

	// Start the server on the other end, possibly.
	// There are two cases in which we do this: (1) we want
	// a local loopback server in standalone mode; (2) we
	// need to "autofork" it. Do at most one of these
	// operations.
	if g.Env.GetStandalone() {
		if cl.IsNoStandalone() {
			return fmt.Errorf("Can't run command in standalone mode")
		}
		if err := service.NewService(false /* isDaemon */, g).StartLoopbackServer(); err != nil {
			if pflerr, ok := err.(libkb.PIDFileLockError); ok {
				err = fmt.Errorf("Can't run in standalone mode with a service running (see %q)",
					pflerr.Filename)
			}
			return err
		}
	} else {
		// If this command warrants an autofork, do it now.
		if fc := cl.GetForkCmd(); fc == libcmdline.ForceFork || (g.Env.GetAutoFork() && fc != libcmdline.NoFork) {
			if err = client.ForkServer(cl, g); err != nil {
				return err
			}
		}
		// Whether or not we autoforked, we're now running in client-server
		// mode (as opposed to standalone). Register a global LogUI so that
		// calls to G.Log() in the daemon can be copied to us. This is
		// something of a hack on the daemon side.
		if !g.Env.GetDoLogForward() {
			g.Log.Debug("Disabling log forwarding")
		} else {
			// TODO This triggers a connection to the RPC server before cmd.Run() is
			// called, so the command has no way to deal with errors on its own.
			// This should probably be moved into RegisterProtocols?
			// Also rpc.RegisterProtocolsWithContext seems to automatically add the
			// LogUIProtocol?
			err := registerGlobalLogUI(g)
			if err != nil {
				return err
			}
		}
	}

	return cmd.Run()
}