本文整理汇总了Golang中github.com/juju/cmd.Context.GetStderr方法的典型用法代码示例。如果您正苦于以下问题:Golang Context.GetStderr方法的具体用法?Golang Context.GetStderr怎么用?Golang Context.GetStderr使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类github.com/juju/cmd.Context
的用法示例。
在下文中一共展示了Context.GetStderr方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: handleBootstrapError
// handleBootstrapError is called to clean up if bootstrap fails.
func handleBootstrapError(ctx *cmd.Context, err error, cleanup func()) {
ch := make(chan os.Signal, 1)
ctx.InterruptNotify(ch)
defer ctx.StopInterruptNotify(ch)
defer close(ch)
go func() {
for _ = range ch {
fmt.Fprintln(ctx.GetStderr(), "Cleaning up failed bootstrap")
}
}()
cleanup()
}
示例2: handleBootstrapError
// handleBootstrapError is called to clean up if bootstrap fails.
func handleBootstrapError(ctx *cmd.Context, err error, cleanup func() error) {
ch := make(chan os.Signal, 1)
ctx.InterruptNotify(ch)
defer ctx.StopInterruptNotify(ch)
defer close(ch)
go func() {
for _ = range ch {
fmt.Fprintln(ctx.GetStderr(), "Cleaning up failed bootstrap")
}
}()
if err := cleanup(); err != nil {
logger.Errorf("error cleaning up: %v", err)
}
}
示例3: Run
//.........这里部分代码省略.........
return ambiguousCredentialError
}
if errors.IsNotFound(err) && c.CredentialName == "" {
// No credential was explicitly specified, and no credential
// was found in credentials.yaml; have the provider detect
// credentials from the environment.
ctx.Verbosef("no credentials found, checking environment")
detected, err := modelcmd.DetectCredential(c.Cloud, cloud.Type)
if errors.Cause(err) == modelcmd.ErrMultipleCredentials {
return ambiguousDetectedCredentialError
} else if err != nil {
return errors.Trace(err)
}
// We have one credential so extract it from the map.
var oneCredential jujucloud.Credential
for detectedCredentialName, oneCredential = range detected.AuthCredentials {
}
credential = &oneCredential
regionName = c.Region
if regionName == "" {
regionName = detected.DefaultRegion
}
logger.Debugf(
"authenticating with region %q and credential %q (%v)",
regionName, detectedCredentialName, credential.Label,
)
logger.Tracef("credential: %v", credential)
} else if err != nil {
return errors.Trace(err)
}
region, err := getRegion(cloud, c.Cloud, regionName)
if err != nil {
fmt.Fprintf(ctx.GetStderr(),
"%s\n\nSpecify an alternative region, or try %q.",
err, "juju update-clouds",
)
return cmd.ErrSilent
}
controllerModelUUID, err := utils.NewUUID()
if err != nil {
return errors.Trace(err)
}
hostedModelUUID, err := utils.NewUUID()
if err != nil {
return errors.Trace(err)
}
controllerUUID, err := utils.NewUUID()
if err != nil {
return errors.Trace(err)
}
// Create a model config, and split out any controller
// and bootstrap config attributes.
modelConfigAttrs := map[string]interface{}{
"type": cloud.Type,
"name": bootstrap.ControllerModelName,
config.UUIDKey: controllerModelUUID.String(),
}
userConfigAttrs, err := c.config.ReadAttrs(ctx)
if err != nil {
return errors.Trace(err)
}
// The provider may define some custom attributes specific
示例4: Run
func (c *runCommand) Run(ctx *cmd.Context) error {
client, err := getRunAPIClient(c)
if err != nil {
return err
}
defer client.Close()
var runResults []params.ActionResult
if c.all {
runResults, err = client.RunOnAllMachines(c.commands, c.timeout)
} else {
params := params.RunParams{
Commands: c.commands,
Timeout: c.timeout,
Machines: c.machines,
Services: c.services,
Units: c.units,
}
runResults, err = client.Run(params)
}
if err != nil {
return block.ProcessBlockedError(err, block.BlockChange)
}
actionsToQuery := []actionQuery{}
for _, result := range runResults {
if result.Error != nil {
fmt.Fprintf(ctx.GetStderr(), "couldn't queue one action: %v", result.Error)
continue
}
actionTag, err := names.ParseActionTag(result.Action.Tag)
if err != nil {
fmt.Fprintf(ctx.GetStderr(), "got invalid action tag %v for receiver %v", result.Action.Tag, result.Action.Receiver)
continue
}
receiverTag, err := names.ActionReceiverFromTag(result.Action.Receiver)
if err != nil {
fmt.Fprintf(ctx.GetStderr(), "got invalid action receiver tag %v for action %v", result.Action.Receiver, result.Action.Tag)
continue
}
var receiverType string
switch receiverTag.(type) {
case names.UnitTag:
receiverType = "UnitId"
case names.MachineTag:
receiverType = "MachineId"
default:
receiverType = "ReceiverId"
}
actionsToQuery = append(actionsToQuery, actionQuery{
actionTag: actionTag,
receiver: actionReceiver{
receiverType: receiverType,
tag: receiverTag,
}})
}
if len(actionsToQuery) == 0 {
return errors.New("no actions were successfully enqueued, aborting")
}
values := []interface{}{}
for len(actionsToQuery) > 0 {
actionResults, err := client.Actions(entities(actionsToQuery))
if err != nil {
return errors.Trace(err)
}
newActionsToQuery := []actionQuery{}
for i, result := range actionResults.Results {
if result.Error == nil {
switch result.Status {
case params.ActionRunning, params.ActionPending:
newActionsToQuery = append(newActionsToQuery, actionsToQuery[i])
continue
}
}
values = append(values, ConvertActionResults(result, actionsToQuery[i]))
}
actionsToQuery = newActionsToQuery
// TODO: use a watcher instead of sleeping
// this should be easier once we implement action grouping
<-afterFunc(1 * time.Second)
}
// If we are just dealing with one result, AND we are using the smart
// format, then pretend we were running it locally.
if len(values) == 1 && c.out.Name() == "smart" {
result, ok := values[0].(map[string]interface{})
if !ok {
return errors.New("couldn't read action output")
}
if res, ok := result["Error"].(string); ok {
return errors.New(res)
}
//.........这里部分代码省略.........