forked from Azure/azure-dev
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathenv_flag.go
32 lines (25 loc) · 1021 Bytes
/
env_flag.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.
package internal
import (
"os"
"github.com/spf13/pflag"
)
// EnvFlag is a flag that represents the environment name. Actions which inject an environment should also use this flag
// so the user can control what environment is loaded in a uniform way across all our commands.
type EnvFlag struct {
EnvironmentName string
}
// EnvironmentNameFlagName is the full name of the flag as it appears on the command line.
const EnvironmentNameFlagName string = "environment"
// envNameEnvVarName is the same as environment.EnvNameEnvVarName, but duplicated here to prevent an import cycle.
const envNameEnvVarName = "AZURE_ENV_NAME"
func (e *EnvFlag) Bind(local *pflag.FlagSet, global *GlobalCommandOptions) {
local.StringVarP(
&e.EnvironmentName,
EnvironmentNameFlagName,
"e",
// Set the default value to AZURE_ENV_NAME value if available
os.Getenv(envNameEnvVarName),
"The name of the environment to use.")
}