本文整理汇总了Golang中github.com/coreos/fleet/third_party/github.com/codegangsta/cli.Context.String方法的典型用法代码示例。如果您正苦于以下问题:Golang Context.String方法的具体用法?Golang Context.String怎么用?Golang Context.String使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类github.com/coreos/fleet/third_party/github.com/codegangsta/cli.Context
的用法示例。
在下文中一共展示了Context.String方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: sshAction
func sshAction(c *cli.Context) {
unit := c.String("unit")
machine := c.String("machine")
if unit != "" && machine != "" {
log.Fatal("Both flags, machine and unit provided, please specify only one")
}
args := c.Args()
var err error
var addr string
switch {
case machine != "":
addr, _ = findAddressInMachineList(machine)
case unit != "":
addr, _ = findAddressInRunningUnits(unit)
default:
addr, err = globalMachineLookup(args)
args = args[1:]
}
if err != nil {
log.Fatal(err)
}
if addr == "" {
log.Fatalf("Requested machine could not be found")
}
agentForwarding := c.Bool("agent")
var sshClient *ssh.SSHForwardingClient
if tun := getTunnelFlag(); tun != "" {
sshClient, err = ssh.NewTunnelledSSHClient("core", tun, addr, getChecker(), agentForwarding)
} else {
sshClient, err = ssh.NewSSHClient("core", addr, getChecker(), agentForwarding)
}
if err != nil {
log.Fatal(err.Error())
return
}
defer sshClient.Close()
if len(args) > 0 {
cmd := strings.Join(args, " ")
channel, err := ssh.Execute(sshClient, cmd)
if err != nil {
log.Fatalf("Unable to run command over SSH: %s", err.Error())
}
readSSHChannel(channel)
} else {
if err := ssh.Shell(sshClient); err != nil {
log.Fatalf(err.Error())
}
}
}
示例2: startUnitAction
func startUnitAction(c *cli.Context) {
var err error
r := getRegistry()
payloads := make([]job.JobPayload, len(c.Args()))
for i, v := range c.Args() {
name := path.Base(v)
payload := r.GetPayload(name)
if payload == nil {
payload, err = getJobPayloadFromFile(v)
if err != nil {
fmt.Println(err.Error())
return
}
err = r.CreatePayload(payload)
if err != nil {
fmt.Printf("Creation of payload %s failed: %v\n", payload.Name, err)
return
}
}
payloads[i] = *payload
}
requirements := parseRequirements(c.String("require"))
// TODO: This must be done in a transaction!
for _, jp := range payloads {
j := job.NewJob(jp.Name, requirements, &jp, nil)
err := r.CreateJob(j)
if err != nil {
fmt.Printf("Creation of job %s failed: %v\n", j.Name, err)
}
}
}
示例3: startUnitAction
func startUnitAction(c *cli.Context) {
var err error
// If signing is explicitly set to on, verification will be done also.
toSign := c.Bool("sign")
var sc *sign.SignatureCreator
var sv *sign.SignatureVerifier
if toSign {
var err error
sc, err = sign.NewSignatureCreatorFromSSHAgent()
if err != nil {
fmt.Println("Fail to create SignatureCreator:", err)
return
}
sv, err = sign.NewSignatureVerifierFromSSHAgent()
if err != nil {
fmt.Println("Fail to create SignatureVerifier:", err)
return
}
}
payloads := make([]job.JobPayload, len(c.Args()))
for i, v := range c.Args() {
name := path.Base(v)
payload := registryCtl.GetPayload(name)
if payload == nil {
payload, err = getJobPayloadFromFile(v)
if err != nil {
fmt.Println(err.Error())
return
}
err = registryCtl.CreatePayload(payload)
if err != nil {
fmt.Printf("Creation of payload %s failed: %v\n", payload.Name, err)
return
}
if toSign {
s, err := sc.SignPayload(payload)
if err != nil {
fmt.Printf("Creation of sign for payload %s failed: %v\n", payload.Name, err)
return
}
registryCtl.CreateSignatureSet(s)
}
}
if toSign {
s := registryCtl.GetSignatureSetOfPayload(name)
ok, err := sv.VerifyPayload(payload, s)
if !ok || err != nil {
fmt.Printf("Check of payload %s failed: %v\n", payload.Name, err)
return
}
}
payloads[i] = *payload
}
requirements := parseRequirements(c.String("require"))
// TODO: This must be done in a transaction!
for _, jp := range payloads {
j := job.NewJob(jp.Name, requirements, &jp, nil)
err := registryCtl.CreateJob(j)
if err != nil {
fmt.Printf("Creation of job %s failed: %v\n", j.Name, err)
}
}
}
示例4: sshAction
func sshAction(c *cli.Context) {
unit := c.String("unit")
machine := c.String("machine")
if unit != "" && machine != "" {
log.Fatal("Both flags, machine and unit provided, please specify only one")
}
args := c.Args()
var err error
var addr string
switch {
case machine != "":
addr, _ = findAddressInMachineList(machine)
case unit != "":
addr, _ = findAddressInRunningUnits(unit)
default:
addr, err = globalMachineLookup(args)
args = args[1:]
}
if err != nil {
log.Fatal(err)
}
if addr == "" {
log.Fatalf("Requested machine could not be found")
}
var sshClient *gossh.ClientConn
if tun := getTunnelFlag(); tun != "" {
sshClient, err = ssh.NewTunnelledSSHClient("core", tun, addr)
} else {
sshClient, err = ssh.NewSSHClient("core", addr)
}
if err != nil {
log.Fatal(err.Error())
return
}
defer sshClient.Close()
if len(args) > 0 {
cmd := strings.Join(args, " ")
stdout, err := ssh.Execute(sshClient, cmd)
if err != nil {
log.Fatalf("Unable to run command over SSH: %s", err.Error())
}
for {
bytes, prefix, err := stdout.ReadLine()
if err != nil {
break
}
fmt.Print(string(bytes))
if !prefix {
fmt.Print("\n")
}
}
} else {
if err := ssh.Shell(sshClient); err != nil {
log.Fatalf(err.Error())
}
}
}
示例5: sshAction
func sshAction(c *cli.Context) {
r := getRegistry(c)
args := c.Args()
unit := c.String("unit")
if len(args) == 0 && unit == "" {
log.Fatalf("Provide one machine or unit")
}
var addr string
if unit == "" {
lookup := args[0]
args = args[1:]
states := r.GetActiveMachines()
var match *machine.MachineState
for i, _ := range states {
machState := states[i]
if !strings.HasPrefix(machState.BootId, lookup) {
continue
} else if match != nil {
log.Fatalf("Found more than one Machine, be more specfic")
}
match = &machState
}
if match == nil {
log.Fatalf("Could not find provided Machine")
}
addr = fmt.Sprintf("%s:22", match.PublicIP)
} else {
js := r.GetJobState(unit)
if js == nil {
log.Fatalf("Requested unit %s does not appear to be running", unit)
}
addr = fmt.Sprintf("%s:22", js.MachineState.PublicIP)
}
var err error
var sshClient *gossh.ClientConn
if tun := getTunnelFlag(c); tun != "" {
sshClient, err = ssh.NewTunnelledSSHClient("core", tun, addr)
} else {
sshClient, err = ssh.NewSSHClient("core", addr)
}
if err != nil {
log.Fatalf("Unable to establish SSH connection: %v", err)
return
}
defer sshClient.Close()
if len(args) > 0 {
cmd := strings.Join(args, " ")
stdout, err := ssh.Execute(sshClient, cmd)
if err != nil {
log.Fatalf("Unable to run command over SSH: %s", err.Error())
}
for {
bytes, prefix, err := stdout.ReadLine()
if err != nil {
break
}
print(string(bytes))
if !prefix {
print("\n")
}
}
} else {
if err := ssh.Shell(sshClient); err != nil {
log.Fatalf(err.Error())
}
}
}