本文整理汇总了Golang中github.com/codegangsta/cli.Context.StringSlice方法的典型用法代码示例。如果您正苦于以下问题:Golang Context.StringSlice方法的具体用法?Golang Context.StringSlice怎么用?Golang Context.StringSlice使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类github.com/codegangsta/cli.Context
的用法示例。
在下文中一共展示了Context.StringSlice方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: secretAdd
func secretAdd(c *cli.Context) error {
repo := c.Args().First()
owner, name, err := parseRepo(repo)
if err != nil {
return err
}
tail := c.Args().Tail()
if len(tail) != 2 {
cli.ShowSubcommandHelp(c)
return nil
}
secret := &model.Secret{}
secret.Name = tail[0]
secret.Value = tail[1]
secret.Images = c.StringSlice("image")
secret.Events = c.StringSlice("event")
if len(secret.Images) == 0 {
return fmt.Errorf("Please specify the --image parameter")
}
client, err := newClient(c)
if err != nil {
return err
}
return client.SecretPost(owner, name, secret)
}
示例2: Run
func (cmd *Restart) Run(scope scope.Scope, c *cli.Context) {
if err := net.VerifyLoginURL(cmd.network); err != nil {
error_handler.ErrorExit(err)
}
parms := c.StringSlice("param")
invoke(cmd.network, scope.Application, scope.Entity, restartEffector, parms)
}
示例3: Issues
func Issues(c *cli.Context) {
client := github.GetClient()
repo := git.GetRepo()
params := github.IssueParams{
Milestone: c.String("milestone"),
State: c.String("state"),
Assignee: c.String("assignee"),
Creator: c.String("creator"),
Mentioned: c.String("mentioned"),
Labels: c.StringSlice("label"),
Sort: c.String("sort"),
Direction: c.String("direction"),
Since: c.String("since"),
}
issues, err := client.GetIssues(repo, params)
if err != nil {
log.Fatal(err)
}
bold := false
if len(issues) > 0 {
PrintHeader()
for _, issue := range issues {
PrintIssue(issue, bold)
bold = !bold
}
} else {
fmt.Println("No issues found")
}
}
示例4: 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
}
}
示例5: Setup
func Setup(c *cli.Context) error {
if b, ok := Brokers[c.String("broker")]; ok {
broker.DefaultBroker = b(strings.Split(c.String("broker_address"), ","))
}
if r, ok := Registries[c.String("registry")]; ok {
registry.DefaultRegistry = r(strings.Split(c.String("registry_address"), ","))
}
if t, ok := Transports[c.String("transport")]; ok {
transport.DefaultTransport = t(strings.Split(c.String("transport_address"), ","))
}
metadata := make(map[string]string)
for _, d := range c.StringSlice("server_metadata") {
var key, val string
parts := strings.Split(d, "=")
key = parts[0]
if len(parts) > 1 {
val = strings.Join(parts[1:], "=")
}
metadata[key] = val
}
server.DefaultServer = server.NewServer(
server.Name(c.String("server_name")),
server.Id(c.String("server_id")),
server.Address(c.String("server_address")),
server.Metadata(metadata),
)
client.DefaultClient = client.NewClient()
return nil
}
示例6: cmdRun
func cmdRun(c *cli.Context) error {
s, err := openAndCheck(c)
if err != nil {
return cli.NewExitError(err.Error(), 3)
}
webAddr := c.String("web-addr")
saslPaths := c.StringSlice("sock")
var wg sync.WaitGroup
if webAddr != "" {
wg.Add(1)
go func() {
defer wg.Done()
if err := runWebAddr(webAddr, s.GetInterface(), c.GlobalString("web-static-dir")); err != nil {
fmt.Printf("warning running web interface failed: %s\n", err)
}
}()
}
for _, path := range saslPaths {
p := path
wg.Add(1)
go func() {
defer wg.Done()
if err := runSaslAuthSocket(p, s.GetInterface()); err != nil {
fmt.Printf("warning running auth agent(%s) failed: %s\n", p, err)
}
}()
}
wg.Wait()
return cli.NewExitError(fmt.Sprintf("shutting down since all auth sockets have closed."), 0)
}
示例7: registerAgentFromCli
func registerAgentFromCli(c *cli.Context) *buildbox.Agent {
// Init debugging
if c.Bool("debug") {
buildbox.LoggerInitDebug()
}
agentRegistrationToken := c.String("agent-registration-token")
// Should we look to the environment for the agent registration token?
if agentRegistrationToken == AgentRegistrationTokenDefault {
agentRegistrationToken = os.Getenv(AgentRegistrationTokenDefault)
}
if agentRegistrationToken == "" {
fmt.Println("buildbox-agent: missing agent registration token\nSee 'buildbox-agent register --help'")
os.Exit(1)
}
// Create a client so we can register the agent
var client buildbox.Client
client.AuthorizationToken = agentRegistrationToken
client.URL = c.String("url")
// Register the agent
agentAccessToken, err := client.AgentRegister(c.String("name"), c.StringSlice("meta-data"))
if err != nil {
buildbox.Logger.Fatal(err)
}
// Start the agent using the token we have
return setupAgent("register", agentAccessToken, c.String("bootstrap-script"), c.String("url"))
}
示例8: watchEvents
func watchEvents(c *cli.Context) {
var err error
dockerClient, err = dockeraction.GetDefaultActionClient()
if err != nil {
log.Fatal(err)
}
token := c.String("token")
eventChan := make(chan *docker.APIEvents)
log.Println("Watching for Docker events")
if err := dockerClient.AddEventListener(eventChan); err != nil {
log.Fatal(err)
}
for event := range eventChan {
if event.Status == "start" {
skip := false
for _, i := range c.StringSlice("ignore") {
if i == event.From {
skip = true
break
}
}
if !skip {
go logContainer(event.ID[:12], token)
log.Printf("Log stream for %s started (%s)", event.ID[:12], event.From)
}
}
}
}
示例9: addDevice
func addDevice(spec *specs.LinuxSpec, rspec *specs.LinuxRuntimeSpec, context *cli.Context) error {
for _, devs := range context.StringSlice("device-add") {
dev := strings.Split(devs, ":")
if len(dev) == 8 {
path := dev[0]
rtemp := []rune(dev[1])
typ := rtemp[0]
major, err := strconv.Atoi(dev[2])
minor, err := strconv.Atoi(dev[3])
permi := dev[4]
filemodle, err := strconv.Atoi(dev[5])
fm := os.FileMode(filemodle)
uid, err := strconv.Atoi(dev[6])
gid, err := strconv.Atoi(dev[7])
if err != nil {
return err
}
device := specs.Device{path, typ, int64(major), int64(minor), permi, fm, uint32(uid), uint32(gid)}
rspec.Linux.Devices = append(rspec.Linux.Devices, device)
} else {
return fmt.Errorf("Device-add error: %s", devs)
}
}
return nil
}
示例10: generate
func generate(c *cli.Context) error {
cfg, err := config.LoadConfig()
if err != nil {
return err
}
generateServer := c.Bool("server")
outDir := c.String("dir")
if outDir == "" {
return fmt.Errorf("out directory (-d, --dir) not specified")
}
caCertPath := filepath.Join(outDir, "ca.pem")
caKeyPath := filepath.Join(outDir, "ca-key.pem")
certPath := filepath.Join(outDir, "cert.pem")
keyPath := filepath.Join(outDir, "key.pem")
if generateServer {
certPath = filepath.Join(outDir, "server-cert.pem")
keyPath = filepath.Join(outDir, "server-key.pem")
}
if _, err := os.Stat(outDir); os.IsNotExist(err) {
if err := os.MkdirAll(outDir, 0700); err != nil {
return err
}
}
if err := writeCaCerts(cfg, caCertPath, caKeyPath); err != nil {
return err
}
hostnames := c.StringSlice("hostname")
return writeCerts(generateServer, hostnames, cfg, certPath, keyPath, caCertPath, caKeyPath)
}
示例11: PopulateFlags
// Add the flags accepted by run to the supplied flag set, returning the
// variables into which the flags will parse.
func PopulateFlags(c *cli.Context) (flags *FlagStorage) {
flags = &FlagStorage{
// File system
MountOptions: make(map[string]string),
DirMode: os.FileMode(c.Int("dir-mode")),
FileMode: os.FileMode(c.Int("file-mode")),
Uid: uint32(c.Int("uid")),
Gid: uint32(c.Int("gid")),
// Tuning,
StatCacheTTL: c.Duration("stat-cache-ttl"),
TypeCacheTTL: c.Duration("type-cache-ttl"),
// OSS
Endpoint: c.String("endpoint"),
UsePathRequest: c.Bool("use-path-request"),
Internal: c.Bool("internal"),
// Debugging,
DebugFuse: c.Bool("debug_fuse"),
DebugOSS: c.Bool("debug_oss"),
}
// Handle the repeated "-o" flag.
for _, o := range c.StringSlice("o") {
parseOptions(flags.MountOptions, o)
}
// Get the region/AccessKeyId/AccessKeySecret
flags.AccessKeyId = os.Getenv("ACCESS_KEY_ID")
flags.AccessKeySecret = os.Getenv("ACCESS_KEY_SECRET")
flags.Region = oss.Region(os.Getenv("OSS_REGION"))
return
}
示例12: ServerFromCli
// ServerFromCli uses the cli arguments to configure a server instance
func ServerFromCli(c *cli.Context) *gouncer.Server {
CheckSSL(c)
// Initialize configuration components from cli
core := &gouncer.Core{c.String("hostname"), ":" + c.String("port"), c.Bool("jsonp"), c.String("log")}
ssl := &gouncer.Ssl{c.String("certificate"), c.String("key")}
backend := &gouncer.Backend{
Couchdb: c.String("couchdb"),
Userdb: c.String("userdb"),
Groupdb: c.String("groupdb"),
Memcache: c.StringSlice("memcache"),
Smtp: c.String("smtp"),
}
token := &gouncer.Token{c.String("algorithm"), int32(c.Int("expiration"))}
// Create configuration
cfg := &gouncer.Config{
Core: core,
Ssl: ssl,
Backend: backend,
Token: token,
}
return gouncer.NewServer(cfg)
}
示例13: createMultipPart
func createMultipPart(c *cli.Context) {
buffer := bytes.NewBuffer([]byte{})
mpw := multipart.NewWriter(buffer)
for _, file := range c.StringSlice("file") {
w, err := mpw.CreateFormFile("pulse-plugin", file)
if err != nil {
panic(err)
}
fb, err := ioutil.ReadFile(file)
if err != nil {
panic(err)
}
w.Write(fb)
}
err := mpw.Close()
if err != nil {
panic(err)
}
//print out the multiart file
fmt.Println(buffer.String())
}
示例14: dispatchCommand
func dispatchCommand(c *cli.Context, client *etcd.Client, cmd *command.Command) {
targets := c.StringSlice("target")
if targets == nil || len(targets) == 0 {
log.Warningln("no target set! try to send command to all registered host.")
targets = fetchHosts(c, client)
}
if targets == nil {
log.Fatalln("no target to send command.")
} else {
log.Infoln("send command to: ", targets)
}
for _, target := range targets {
key := fmt.Sprintf("/beacon/commands/single/%s/%s/",
target, cmd.Id)
if c.GlobalString("prefix") != "" {
key = fmt.Sprintf("/%s%s", strings.Trim(c.GlobalString("prefix"), "/"), key)
}
if _, err := client.Set(key, cmd.Marshal(), 0); err != nil {
log.WithFields(log.Fields{
"error": err.Error(),
}).Fatalln("send command failed.")
}
}
}
示例15: createServiceLB
//createServiceLB is a netctl interface routine to delete
//service object
func createServiceLB(ctx *cli.Context) {
if len(ctx.Args()) != 1 {
errExit(ctx, exitHelp, "Service name required", true)
}
serviceName := ctx.Args()[0]
serviceSubnet := ctx.String("network")
tenantName := ctx.String("tenant")
if len(tenantName) == 0 {
tenantName = "default"
}
selectors := ctx.StringSlice("selector")
ports := ctx.StringSlice("port")
ipAddress := ctx.String("preferred-ip")
service := &contivClient.ServiceLB{
ServiceName: serviceName,
TenantName: tenantName,
NetworkName: serviceSubnet,
IpAddress: ipAddress,
}
service.Selectors = append(service.Selectors, selectors...)
service.Ports = append(service.Ports, ports...)
errCheck(ctx, getClient(ctx).ServiceLBPost(service))
fmt.Printf("Creating ServiceLB %s:%s\n", tenantName, serviceName)
}