本文整理汇总了Golang中github.com/urfave/cli.Context.GlobalBool方法的典型用法代码示例。如果您正苦于以下问题:Golang Context.GlobalBool方法的具体用法?Golang Context.GlobalBool怎么用?Golang Context.GlobalBool使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类github.com/urfave/cli.Context
的用法示例。
在下文中一共展示了Context.GlobalBool方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: GetAPIClient
// GetAPIClient is @@@
func (c *CLI) GetAPIClient(ctx *cli.Context) *gondor.Client {
if c.api == nil {
LoadSiteConfig()
if siteCfg.Cluster != "" {
var siteCloud, siteCluster string
if strings.Count(siteCfg.Cluster, "/") == 0 {
siteCluster = siteCfg.Cluster
} else {
parts := strings.Split(siteCfg.Cluster, "/")
siteCloud, siteCluster = parts[0], parts[1]
}
if siteCloud != "" {
cloud, err := c.Config.GetCloudByName(siteCloud)
if err != nil {
fatal(err.Error())
}
c.SetCloud(cloud)
}
if siteCluster != "" {
cluster, err := c.Config.Cloud.GetClusterByName(siteCluster)
if err != nil {
fatal(err.Error())
}
c.SetCluster(cluster)
}
}
httpClient := c.GetHTTPClient(ctx)
c.api = gondor.NewClient(c.Config.GetClientConfig(), httpClient)
if ctx.GlobalBool("log-http") {
c.api.EnableHTTPLogging(true)
}
c.api.SetClientVersion(fmt.Sprintf("%s %s", c.Name, c.Version))
}
return c.api
}
示例2: createContainer
func createContainer(context *cli.Context, id string, spec *specs.Spec) (libcontainer.Container, error) {
config, err := specconv.CreateLibcontainerConfig(&specconv.CreateOpts{
CgroupName: id,
UseSystemdCgroup: context.GlobalBool("systemd-cgroup"),
NoPivotRoot: context.Bool("no-pivot"),
NoNewKeyring: context.Bool("no-new-keyring"),
Spec: spec,
})
if err != nil {
return nil, err
}
if _, err := os.Stat(config.Rootfs); err != nil {
if os.IsNotExist(err) {
return nil, fmt.Errorf("rootfs (%q) does not exist", config.Rootfs)
}
return nil, err
}
factory, err := loadFactory(context)
if err != nil {
return nil, err
}
return factory.Create(id, config)
}
示例3: Run
func (cmd *Login) Run(scope scope.Scope, c *cli.Context) {
if !c.Args().Present() {
error_handler.ErrorExit("A URL must be provided as the first argument", error_handler.CLIUsageErrorExitCode)
}
// If an argument was not supplied, it is set to empty string
cmd.network.BrooklynUrl = c.Args().Get(0)
cmd.network.BrooklynUser = c.Args().Get(1)
cmd.network.BrooklynPass = c.Args().Get(2)
cmd.network.SkipSslChecks = c.GlobalBool("skipSslChecks")
if err := net.VerifyLoginURL(cmd.network); err != nil {
error_handler.ErrorExit(err)
}
// Strip off trailing '/' from URL if present.
if cmd.network.BrooklynUrl[len(cmd.network.BrooklynUrl)-1] == '/' {
if len(cmd.network.BrooklynUrl) == 1 {
error_handler.ErrorExit("URL must not be a single \"/\" character", error_handler.CLIUsageErrorExitCode)
}
cmd.network.BrooklynUrl = cmd.network.BrooklynUrl[0 : len(cmd.network.BrooklynUrl)-1]
}
// Prompt for password if not supplied (password is not echoed to screen
if cmd.network.BrooklynUser != "" && cmd.network.BrooklynPass == "" {
fmt.Print("Enter Password: ")
bytePassword, err := terminal.ReadPassword(int(syscall.Stdin))
if err != nil {
error_handler.ErrorExit(err)
}
fmt.Printf("\n")
cmd.network.BrooklynPass = string(bytePassword)
}
if cmd.config.Map == nil {
cmd.config.Map = make(map[string]interface{})
}
// now persist these credentials to the yaml file
auth, ok := cmd.config.Map["auth"].(map[string]interface{})
if !ok {
auth = make(map[string]interface{})
cmd.config.Map["auth"] = auth
}
auth[cmd.network.BrooklynUrl] = map[string]string{
"username": cmd.network.BrooklynUser,
"password": cmd.network.BrooklynPass,
}
cmd.config.Map["target"] = cmd.network.BrooklynUrl
cmd.config.Map["skipSslChecks"] = cmd.network.SkipSslChecks
cmd.config.Write()
loginVersion, err := version.Version(cmd.network)
if nil != err {
error_handler.ErrorExit(err)
}
fmt.Printf("Connected to Brooklyn version %s at %s\n", loginVersion.Version, cmd.network.BrooklynUrl)
}
示例4: BeforeApp
// BeforeApp is an action that is executed before any cli command.
func BeforeApp(c *cli.Context) error {
if c.GlobalBool("verbose") {
logrus.SetLevel(logrus.DebugLevel)
}
if version.ShowWarning() {
logrus.Warning("Note: This is an experimental alternate implementation of the Compose CLI (https://github.com/docker/compose)")
}
return nil
}
示例5: mustNewAuthAPI
func mustNewAuthAPI(c *cli.Context) client.AuthAPI {
hc := mustNewClient(c)
if c.GlobalBool("debug") {
fmt.Fprintf(os.Stderr, "Cluster-Endpoints: %s\n", strings.Join(hc.Endpoints(), ", "))
}
return client.NewAuthAPI(hc)
}
示例6: mustNewClient
func mustNewClient(c *cli.Context) client.Client {
hc, err := newClient(c)
if err != nil {
fmt.Fprintln(os.Stderr, err.Error())
os.Exit(1)
}
debug := c.GlobalBool("debug")
if debug {
client.EnablecURLDebug()
}
if !c.GlobalBool("no-sync") {
if debug {
fmt.Fprintf(os.Stderr, "start to sync cluster using endpoints(%s)\n", strings.Join(hc.Endpoints(), ","))
}
ctx, cancel := contextWithTotalTimeout(c)
err := hc.Sync(ctx)
cancel()
if err != nil {
if err == client.ErrNoEndpoints {
fmt.Fprintf(os.Stderr, "etcd cluster has no published client endpoints.\n")
fmt.Fprintf(os.Stderr, "Try '--no-sync' if you want to access non-published client endpoints(%s).\n", strings.Join(hc.Endpoints(), ","))
handleError(ExitServerError, err)
}
if isConnectionError(err) {
handleError(ExitBadConnection, err)
}
// fail-back to try sync cluster with peer API. this is for making etcdctl work with etcd 0.4.x.
// TODO: remove this when we deprecate the support for etcd 0.4.
eps, serr := syncWithPeerAPI(c, ctx, hc.Endpoints())
if serr != nil {
if isConnectionError(serr) {
handleError(ExitBadConnection, serr)
} else {
handleError(ExitServerError, serr)
}
}
err = hc.SetEndpoints(eps)
if err != nil {
handleError(ExitServerError, err)
}
}
if debug {
fmt.Fprintf(os.Stderr, "got endpoints(%s) after sync\n", strings.Join(hc.Endpoints(), ","))
}
}
if debug {
fmt.Fprintf(os.Stderr, "Cluster-Endpoints: %s\n", strings.Join(hc.Endpoints(), ", "))
}
return hc
}
示例7: getDiscoveryDomain
func getDiscoveryDomain(c *cli.Context) (domainstr string, insecure bool) {
domainstr = c.GlobalString("discovery-srv")
// Use an environment variable if nothing was supplied on the
// command line
if domainstr == "" {
domainstr = os.Getenv("ETCDCTL_DISCOVERY_SRV")
}
insecure = c.GlobalBool("insecure-discovery") || (os.Getenv("ETCDCTL_INSECURE_DISCOVERY") != "")
return domainstr, insecure
}
示例8: setup
func setup(c *cli.Context) error {
logrus.SetOutput(os.Stderr)
if c.GlobalBool("debug") {
logrus.SetLevel(logrus.DebugLevel)
} else {
logrus.SetLevel(logrus.WarnLevel)
}
return nil
}
示例9: mustNewClientNoSync
func mustNewClientNoSync(c *cli.Context) client.Client {
hc, err := newClient(c)
if err != nil {
fmt.Fprintln(os.Stderr, err.Error())
os.Exit(1)
}
if c.GlobalBool("debug") {
fmt.Fprintf(os.Stderr, "Cluster-Endpoints: %s\n", strings.Join(hc.Endpoints(), ", "))
client.EnablecURLDebug()
}
return hc
}
示例10: ParseConnStr
//parse sql connection string from cli flags
func ParseConnStr(c *cli.Context) string {
otherParams := "sslmode=disable connect_timeout=5"
if c.GlobalBool("ssl") {
otherParams = "sslmode=require connect_timeout=5"
}
return fmt.Sprintf("user=%s dbname=%s password='%s' host=%s port=%s %s",
c.GlobalString("username"),
c.GlobalString("dbname"),
c.GlobalString("pass"),
c.GlobalString("host"),
c.GlobalString("port"),
otherParams,
)
}
示例11: loadFactory
// loadFactory returns the configured factory instance for execing containers.
func loadFactory(context *cli.Context) (libcontainer.Factory, error) {
root := context.GlobalString("root")
abs, err := filepath.Abs(root)
if err != nil {
return nil, err
}
cgroupManager := libcontainer.Cgroupfs
if context.GlobalBool("systemd-cgroup") {
if systemd.UseSystemd() {
cgroupManager = libcontainer.SystemdCgroups
} else {
return nil, fmt.Errorf("systemd cgroup flag passed, but systemd support for managing cgroups is not available")
}
}
return libcontainer.New(abs, cgroupManager, libcontainer.CriuPath(context.GlobalString("criu")))
}
示例12: createContainer
func createContainer(context *cli.Context, id string, spec *specs.Spec) (libcontainer.Container, error) {
config, err := specconv.CreateLibcontainerConfig(&specconv.CreateOpts{
CgroupName: id,
UseSystemdCgroup: context.GlobalBool("systemd-cgroup"),
NoPivotRoot: context.Bool("no-pivot"),
NoNewKeyring: context.Bool("no-new-keyring"),
Spec: spec,
})
if err != nil {
return nil, err
}
factory, err := loadFactory(context)
if err != nil {
return nil, err
}
return factory.Create(id, config)
}
示例13: Populate
// Populate updates the specified docker context based on command line arguments and subcommands.
func Populate(context *docker.Context, c *cli.Context) {
command.Populate(&context.Context, c)
context.ConfigDir = c.String("configdir")
opts := client.Options{}
opts.TLS = c.GlobalBool("tls")
opts.TLSVerify = c.GlobalBool("tlsverify")
opts.TLSOptions.CAFile = c.GlobalString("tlscacert")
opts.TLSOptions.CertFile = c.GlobalString("tlscert")
opts.TLSOptions.KeyFile = c.GlobalString("tlskey")
clientFactory, err := client.NewDefaultFactory(opts)
if err != nil {
logrus.Fatalf("Failed to construct Docker client: %v", err)
}
context.ClientFactory = clientFactory
}
示例14: mustNewClient
func mustNewClient(c *cli.Context) client.Client {
hc, err := newClient(c)
if err != nil {
fmt.Fprintln(os.Stderr, err.Error())
os.Exit(1)
}
debug := c.GlobalBool("debug")
if debug {
client.EnablecURLDebug()
}
if !c.GlobalBool("no-sync") {
if debug {
fmt.Fprintf(os.Stderr, "start to sync cluster using endpoints(%s)\n", strings.Join(hc.Endpoints(), ","))
}
ctx, cancel := contextWithTotalTimeout(c)
err := hc.Sync(ctx)
cancel()
if err != nil {
if err == client.ErrNoEndpoints {
fmt.Fprintf(os.Stderr, "etcd cluster has no published client endpoints.\n")
fmt.Fprintf(os.Stderr, "Try '--no-sync' if you want to access non-published client endpoints(%s).\n", strings.Join(hc.Endpoints(), ","))
handleError(ExitServerError, err)
}
if isConnectionError(err) {
handleError(ExitBadConnection, err)
}
}
if debug {
fmt.Fprintf(os.Stderr, "got endpoints(%s) after sync\n", strings.Join(hc.Endpoints(), ","))
}
}
if debug {
fmt.Fprintf(os.Stderr, "Cluster-Endpoints: %s\n", strings.Join(hc.Endpoints(), ", "))
}
return hc
}
示例15: handleTOS
func handleTOS(c *cli.Context, client *acme.Client, acc *Account) {
// Check for a global accept override
if c.GlobalBool("accept-tos") {
err := client.AgreeToTOS()
if err != nil {
logger().Fatalf("Could not agree to TOS: %s", err.Error())
}
acc.Save()
return
}
reader := bufio.NewReader(os.Stdin)
logger().Printf("Please review the TOS at %s", acc.Registration.TosURL)
for {
logger().Println("Do you accept the TOS? Y/n")
text, err := reader.ReadString('\n')
if err != nil {
logger().Fatalf("Could not read from console: %s", err.Error())
}
text = strings.Trim(text, "\r\n")
if text == "n" {
logger().Fatal("You did not accept the TOS. Unable to proceed.")
}
if text == "Y" || text == "y" || text == "" {
err = client.AgreeToTOS()
if err != nil {
logger().Fatalf("Could not agree to TOS: %s", err.Error())
}
acc.Save()
break
}
logger().Println("Your input was invalid. Please answer with one of Y/y, n or by pressing enter.")
}
}