~juju-qa/ubuntu/xenial/juju/2.0-rc2

« back to all changes in this revision

Viewing changes to src/github.com/juju/juju/cmd/juju/common/flags.go

  • Committer: Nicholas Skaggs
  • Date: 2016-09-30 14:39:30 UTC
  • mfrom: (1.8.1)
  • Revision ID: nicholas.skaggs@canonical.com-20160930143930-vwwhrefh6ftckccy
import upstream

Show diffs side-by-side

added added

removed removed

Lines of Context:
10
10
 
11
11
        "github.com/juju/cmd"
12
12
        "github.com/juju/errors"
 
13
        "github.com/juju/juju/constraints"
13
14
        "github.com/juju/utils"
14
15
        "gopkg.in/yaml.v2"
15
16
)
76
77
        }
77
78
        return strings.Join(strs, " ")
78
79
}
 
80
 
 
81
// WarnConstraintAliases shows a warning to the user that they have used an
 
82
// alias for a constraint that might go away sometime.
 
83
func WarnConstraintAliases(ctx *cmd.Context, aliases map[string]string) {
 
84
        for alias, canonical := range aliases {
 
85
                ctx.Infof("Warning: constraint %q is deprecated in favor of %q.\n", alias, canonical)
 
86
        }
 
87
}
 
88
 
 
89
// ParseConstraints parses the given constraints and uses WarnConstraintAliases
 
90
// if any aliases were used.
 
91
func ParseConstraints(ctx *cmd.Context, cons string) (constraints.Value, error) {
 
92
        if cons == "" {
 
93
                return constraints.Value{}, nil
 
94
        }
 
95
        constraint, aliases, err := constraints.ParseWithAliases(cons)
 
96
        // we always do these, even on errors, so that the error messages have
 
97
        // context.
 
98
        for alias, canonical := range aliases {
 
99
                ctx.Infof("Warning: constraint %q is deprecated in favor of %q.\n", alias, canonical)
 
100
        }
 
101
        if err != nil {
 
102
                return constraints.Value{}, err
 
103
        }
 
104
        return constraint, nil
 
105
}