Exemple #1
0
func TestApp_RunAsSubcommandParseFlags(t *testing.T) {
	var context *cli.Context

	a := cli.NewApp()
	a.Commands = []cli.Command{
		{
			Name: "foo",
			Action: func(c *cli.Context) {
				context = c
			},
			Flags: []cli.Flag{
				cli.StringFlag{
					Name:  "lang",
					Value: "english",
					Usage: "language for the greeting",
				},
			},
			Before: func(_ *cli.Context) error { return nil },
		},
	}
	a.Run([]string{"", "foo", "--lang", "spanish", "abcd"})

	expect(t, context.Args().Get(0), "abcd")
	expect(t, context.String("lang"), "spanish")
}
Exemple #2
0
func ActivateProfile(c *cli.Context) {
	profile := c.String("profile")

	fmt.Printf("activating profile %s\n", profile)

	var filename, err = checkForShell()

	filename, err = tilde.Expand(filename)
	if err != nil {
		panic(err)
	}
	found, lines := scanFileForVariable(filename, profileVariable, profile)
	if !found {
		lines = append(lines, fmt.Sprintf("export %s=%s", profileVariable, profile))
	}

	writeFile(filename, lines)
}
Exemple #3
0
func BeforeActivateProfile(c *cli.Context) error {
	if !c.IsSet("profile") {
		cli.ShowSubcommandHelp(c)
		output := "Missing required option 'profile'"
		fmt.Println(output)
		return errors.New(output)
	}

	shell := os.Getenv("SHELL")
	if Shells()[shell] == "" {
		output := fmt.Sprintf("Sorry, %s is not a supported shell", shell)
		fmt.Println(output)
		return errors.New(output)
	}

	var filename, _ = tilde.Expand(Shells()[shell])
	if _, err := os.Stat(filename); os.IsNotExist(err) {
		output := fmt.Sprintf("File %s not found", Shells()[shell])
		fmt.Println(output)
		return errors.New(output)
	}

	return nil
}
package lowprofile

import (
	"errors"
	"flag"
	"github.com/kellyp/lowprofile/Godeps/_workspace/src/github.com/codegangsta/cli"
	. "github.com/kellyp/lowprofile/Godeps/_workspace/src/github.com/onsi/ginkgo"
	. "github.com/kellyp/lowprofile/Godeps/_workspace/src/github.com/onsi/gomega"
	"io/ioutil"
	"os"
	"strings"
)

var _ = Describe("Deactivate", func() {
	var (
		context *cli.Context
		set     *flag.FlagSet
	)

	BeforeEach(func() {
		os.Clearenv()

		set = flag.NewFlagSet("test", 0)
		set.String("profile", "profile-name", "doc")
		command := cli.Command{Name: "ap"}
		context = cli.NewContext(nil, set, nil)
		context.Command = command

		set.Set("profile", "some-profile")
	})

	Context("When the shell is not supported", func() {