当前位置: 首页>>代码示例>>Golang>>正文


Golang Context.Bool方法代码示例

本文整理汇总了Golang中github.com/codegangsta/cli.Context.Bool方法的典型用法代码示例。如果您正苦于以下问题:Golang Context.Bool方法的具体用法?Golang Context.Bool怎么用?Golang Context.Bool使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在github.com/codegangsta/cli.Context的用法示例。


在下文中一共展示了Context.Bool方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。

示例1: Run

func (cmd *OrgUsers) Run(c *cli.Context) {
	org := cmd.orgReq.GetOrganization()
	all := c.Bool("a")

	cmd.ui.Say("Getting users in org %s as %s...",
		terminal.EntityNameColor(org.Name),
		terminal.EntityNameColor(cmd.config.Username()),
	)

	roles := orgRoles
	if all {
		roles = []string{models.ORG_USER}
	}

	for _, role := range roles {
		displayName := orgRoleToDisplayName[role]

		users, apiErr := cmd.userRepo.ListUsersInOrgForRole(org.Guid, role)

		cmd.ui.Say("")
		cmd.ui.Say("%s", terminal.HeaderColor(displayName))

		for _, user := range users {
			cmd.ui.Say("  %s", user.Username)
		}

		if apiErr != nil {
			cmd.ui.Failed("Failed fetching org-users for role %s.\n%s", apiErr.Error(), displayName)
			return
		}
	}
}
开发者ID:nota-ja,项目名称:cli,代码行数:32,代码来源:org_users.go

示例2: delete

// delete is a subcommand to delete a snippet.
func delete(c *cli.Context) {
	force := c.Bool("f")
	snippetName := c.Args().First()
	if len(snippetName) == 0 {
		log.Fatal("please enter snippet name")
	}

	s := NewSnippet(conf.SnippetDirectory, snippetName)

	if !s.Exists() {
		log.Fatal("This snippet doesn't exists.")
	}

	if !force {
		reader := bufio.NewReader(os.Stdin)
		fmt.Print("sure you want to delete %s [yn]?")
		ret, err := reader.ReadString('\n')
		if err != nil {
			log.Fatal(err)
		}

		if ret != "y\n" {
			return
		}
	}

	if err := s.Delete(); err != nil {
		log.Fatal(err)
	}

	fmt.Printf("%s has been deleted.\n", snippetName)
}
开发者ID:sudix,项目名称:chickenhead,代码行数:33,代码来源:main.go

示例3: generate

func generate(c *cli.Context) error {
	generateServer := c.Bool("server")
	outDir := c.String("dir")
	hostnames := c.StringSlice("hostname")

	return Generate(generateServer, outDir, hostnames)
}
开发者ID:rowhit,项目名称:os,代码行数:7,代码来源:tlsconf.go

示例4: createBuildpack

func (cmd CreateBuildpack) createBuildpack(buildpackName string, c *cli.Context) (buildpack models.Buildpack, apiErr error) {
	position, err := strconv.Atoi(c.Args()[2])
	if err != nil {
		apiErr = errors.NewWithFmt("Invalid position. %s", err.Error())
		return
	}

	enabled := c.Bool("enable")
	disabled := c.Bool("disable")
	if enabled && disabled {
		apiErr = errors.New("Cannot specify both enabled and disabled.")
		return
	}

	var enableOption *bool = nil
	if enabled {
		enableOption = &enabled
	}
	if disabled {
		disabled = false
		enableOption = &disabled
	}

	buildpack, apiErr = cmd.buildpackRepo.Create(buildpackName, &position, enableOption, nil)

	return
}
开发者ID:nota-ja,项目名称:cli,代码行数:27,代码来源:create_buildpack.go

示例5: getAppParamsFromManifest

func (cmd *Push) getAppParamsFromManifest(c *cli.Context) []models.AppParams {
	if c.Bool("no-manifest") {
		return []models.AppParams{}
	}

	var path string
	if c.String("f") != "" {
		path = c.String("f")
	} else {
		var err error
		path, err = os.Getwd()
		if err != nil {
			cmd.ui.Failed(T("Could not determine the current working directory!"), err)
		}
	}

	m, err := cmd.manifestRepo.ReadManifest(path)

	if err != nil {
		if m.Path == "" && c.String("f") == "" {
			return []models.AppParams{}
		} else {
			cmd.ui.Failed(T("Error reading manifest file:\n{{.Err}}", map[string]interface{}{"Err": err.Error()}))
		}
	}

	apps, err := m.Applications()
	if err != nil {
		cmd.ui.Failed("Error reading manifest file:\n%s", err)
	}

	cmd.ui.Say(T("Using manifest file {{.Path}}\n",
		map[string]interface{}{"Path": terminal.EntityNameColor(m.Path)}))
	return apps
}
开发者ID:ramirito,项目名称:cli,代码行数:35,代码来源:push.go

示例6: newBuilder

func newBuilder(c *cli.Context) builder.Builder {
	db, err := docker.NewBuilderFromEnv()
	if err != nil {
		must(err)
	}
	db.DryRun = c.Bool("dry")
	db.Image = c.String("builder.image")

	g := builder.NewGitHubClient(c.String("github.token"))

	var backend builder.Builder = builder.UpdateGitHubCommitStatus(db, g, fmt.Sprintf(logsURLTemplate, c.String("url")))

	if uri := c.String("stats"); uri != "" {
		u := urlParse(uri)

		switch u.Scheme {
		case "dogstatsd":
			c, err := statsd.New(u.Host)
			must(err)

			backend = datadog.WithStats(
				backend,
				c,
			)
		default:
			must(fmt.Errorf("Unknown stats backend: %v", u.Scheme))
		}
	}

	b := worker.NewBuilder(backend)
	b.Reporter = newReporter(c)

	return b
}
开发者ID:atmos,项目名称:conveyor,代码行数:34,代码来源:factories.go

示例7: secretParseCmd

func secretParseCmd(name string, value string, c *cli.Context) (*model.Secret, error) {
	secret := &model.Secret{}
	secret.Name = name
	secret.Value = value
	secret.Images = c.StringSlice("image")
	secret.Events = c.StringSlice("event")
	secret.SkipVerify = c.Bool("skip-verify")
	secret.Conceal = c.Bool("conceal")

	if len(secret.Images) == 0 {
		return nil, fmt.Errorf("Please specify the --image parameter")
	}

	// TODO(bradrydzewski) below we use an @ sybmol to denote that the secret
	// value should be loaded from a file (inspired by curl). I'd prefer to use
	// a --input flag to explicitly specify a filepath instead.

	if strings.HasPrefix(secret.Value, "@") {
		path := secret.Value[1:]
		out, ferr := ioutil.ReadFile(path)
		if ferr != nil {
			return nil, ferr
		}
		secret.Value = string(out)
	}

	return secret, nil
}
开发者ID:donny-dont,项目名称:drone,代码行数:28,代码来源:secret.go

示例8: Run

func (cmd ListStack) Run(c *cli.Context) {
	stackName := c.Args()[0]

	stack, apiErr := cmd.stacksRepo.FindByName(stackName)

	if c.Bool("guid") {
		cmd.ui.Say(stack.Guid)
	} else {
		if apiErr != nil {
			cmd.ui.Failed(apiErr.Error())
			return
		}

		cmd.ui.Say(T("Getting stack '{{.Stack}}' in org {{.OrganizationName}} / space {{.SpaceName}} as {{.Username}}...",
			map[string]interface{}{"Stack": stackName,
				"OrganizationName": terminal.EntityNameColor(cmd.config.OrganizationFields().Name),
				"SpaceName":        terminal.EntityNameColor(cmd.config.SpaceFields().Name),
				"Username":         terminal.EntityNameColor(cmd.config.Username())}))

		cmd.ui.Ok()
		cmd.ui.Say("")

		table := terminal.NewTable(cmd.ui, []string{T("name"), T("description")})
		table.Add(stack.Name, stack.Description)
		table.Print()
	}
}
开发者ID:tools-alexuser01,项目名称:cli,代码行数:27,代码来源:stack.go

示例9: run

func run(c *cli.Context) {
	plugin := Plugin{
		Mount:   c.StringSlice("mount"),
		Path:    c.String("path"),
		Repo:    c.String("repo.name"),
		Default: c.String("repo.branch"),
		Branch:  c.String("commit.branch"),
	}

	sftp, err := sftp.New(
		c.String("server"),
		c.String("username"),
		c.String("password"),
		c.String("key"),
	)
	if err != nil {
		log.Fatal(err)
	}
	defer sftp.(io.Closer).Close()

	if c.Bool("rebuild") {
		now := time.Now()
		err = plugin.Rebuild(sftp)
		log.Printf("cache built in %v", time.Since(now))
	}
	if c.Bool("restore") {
		now := time.Now()
		err = plugin.Restore(sftp)
		log.Printf("cache restored in %v", time.Since(now))
	}

	if err != nil {
		log.Println(err) // this plugins does not fail on error
	}
}
开发者ID:ZombieHippie,项目名称:drone-sftp-cache,代码行数:35,代码来源:main.go

示例10: RunApp

func RunApp(c *cli.Context) {
	dbUrl := c.String("db-url")

	if dbUrl == "" {
		showErrorAndAbort("you need to provide 'db-url' or $DATABASE_URL needs to be set")
	}

	if c.Bool("debug") {
		logger.SetLevel(loggo.Debug)
	}

	if c.Bool("quiet") {
		logger.SetLevel(loggo.Warning)
	}

	fixturesPaths := GetFixturesDirectories(c.String("fixtures-path"), c.String("env"))
	logger.Debugf("searching for fixtures in: %v", fixturesPaths)

	fixtures, err := LoadDirectories(fixturesPaths)
	if err != nil {
		showErrorAndAbort(err.Error())
	}
	logger.Debugf("found the following fixtures: %+v", fixtures)

	logger.Infof("connecting to DB %s", dbUrl)

	populator, err := NewPopulator(dbUrl)
	if err != nil {
		showErrorAndAbort(err.Error())
	}

	if err := populator.PopulateData(fixtures); err != nil {
		showErrorAndAbort(err.Error())
	}
}
开发者ID:claudetech,项目名称:dbpopulate,代码行数:35,代码来源:main.go

示例11: images

func images(c *cli.Context) {
	filter := "my_images"
	if c.Bool("global") {
		filter = "global"
	}

	images, err := docli.GetImages(filter)
	if err != nil {
		fatalf(err.Error())
	}

	switch filter {
	case "global":
		fmt.Println("Global Images:")
	default:
		fmt.Println("My Images:")
	}

	for _, i := range images {
		fmt.Printf("%s (slug: %s id: %d)\n",
			i.Name,
			i.Slug,
			i.ID)
	}
}
开发者ID:kajali,项目名称:fish,代码行数:25,代码来源:images.go

示例12: doGet

func doGet(c *cli.Context) {
	argURL := c.Args().Get(0)
	doUpdate := c.Bool("update")

	if argURL == "" {
		cli.ShowCommandHelp(c, "get")
		os.Exit(1)
	}

	url, err := url.Parse(argURL)
	utils.DieIf(err)

	if !url.IsAbs() {
		url.Scheme = "https"
		url.Host = "github.com"
		if url.Path[0] != '/' {
			url.Path = "/" + url.Path
		}
	}

	remote, err := NewRemoteRepository(url)
	utils.DieIf(err)

	if remote.IsValid() == false {
		utils.Log("error", fmt.Sprintf("Not a valid repository: %s", url))
		os.Exit(1)
	}

	getRemoteRepository(remote, doUpdate)
}
开发者ID:kentaro,项目名称:ghq,代码行数:30,代码来源:commands.go

示例13: runApp

func runApp(c *cli.Context) {
	debug := c.Bool("debug")

	if err := validateCLI(c); err != nil {
		log.Println("CLI Validation Error:", err)
		cli.ShowAppHelp(c)
		os.Exit(1)
	}

	if !debug {
		TurnOffLogging()
	}

	var sitemap *domain.Sitemap
	if useSavedResults(c) {
		sitemap = runSitemapLoader(c)
	} else {
		sitemap = runSitemapBuilder(c)
	}

	if sitemap == nil {
		fmt.Println("Could not build Sitemap")
		return
	}

	outputSitemapToConsole(c, sitemap)

	if shouldSaveResults(c) {
		outputSitemapToFile(c, sitemap)
	}
}
开发者ID:mkboudreau,项目名称:sitemap,代码行数:31,代码来源:command.go

示例14: runVerify

func runVerify(c *cli.Context) {
	config := common.NewConfig()
	err := config.LoadConfig(c.String("config"))
	if err != nil {
		log.Fatalln(err)
		return
	}

	// verify if runner exist
	runners := []*common.RunnerConfig{}
	for _, runner := range config.Runners {
		if common.VerifyRunner(runner.URL, runner.Token) {
			runners = append(runners, runner)
		}
	}

	if !c.Bool("delete") {
		return
	}

	// check if anything changed
	if len(config.Runners) == len(runners) {
		return
	}

	config.Runners = runners

	// save config file
	err = config.SaveConfig(c.String("config"))
	if err != nil {
		log.Fatalln("Failed to update", c.String("config"), err)
	}
	log.Println("Updated", c.String("config"))
}
开发者ID:AdrianoJS,项目名称:gitlab-ci-multi-runner,代码行数:34,代码来源:verify.go

示例15: takeCmd

//Assign a pull request to the current user.
// If it's taken, show a message with the "--steal" optional flag.
//If the user doesn't have permissions, add a comment #volunteer
func takeCmd(c *cli.Context) {
	if !c.Args().Present() {
		gordon.Fatalf("usage: take ID")
	}
	number := c.Args()[0]
	pr, err := m.GetPullRequest(number)
	if err != nil {
		gordon.Fatalf("%s", err)
	}
	user, err := m.GetGithubUser()
	if err != nil {
		gordon.Fatalf("%s", err)
	}
	if pr.Assignee != nil && !c.Bool("steal") {
		gordon.Fatalf("Use --steal to steal the PR from %s", pr.Assignee.Login)
	}
	pr.Assignee = user
	patchedPR, err := m.PatchPullRequest(number, pr)
	if err != nil {
		gordon.Fatalf("%s", err)
	}
	if patchedPR.Assignee.Login != user.Login {
		m.AddComment(number, "#volunteer")
		fmt.Printf("No permission to assign. You '%s' was added as #volunteer.\n", user.Login)
	} else {
		m.AddComment(number, fmt.Sprintf("#assignee=%s", patchedPR.Assignee.Login))
		fmt.Printf("Assigned PR %s to %s\n", brush.Green(number), patchedPR.Assignee.Login)
	}
}
开发者ID:pombredanne,项目名称:pulls,代码行数:32,代码来源:main.go


注:本文中的github.com/codegangsta/cli.Context.Bool方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。