本文整理汇总了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
}
}
}
示例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)
}
示例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)
}
示例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
}
示例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
}
示例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
}
示例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
}
示例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()
}
}
示例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
}
}
示例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())
}
}
示例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)
}
}
示例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)
}
示例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)
}
}
示例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"))
}
示例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)
}
}