2022-10-10 15:04:15 -04:00
package deployment
import (
"flag"
2022-10-11 11:16:19 -04:00
"fmt"
2022-10-10 15:04:15 -04:00
"os"
"path/filepath"
"reflect"
"time"
"github.com/coreos/go-oidc/v3/oidc"
"github.com/spf13/pflag"
"github.com/coder/coder/cli/cliflag"
2022-10-11 11:16:19 -04:00
"github.com/coder/coder/cli/cliui"
2022-10-10 15:04:15 -04:00
"github.com/coder/coder/codersdk"
)
const (
secretValue = "********"
)
2022-10-11 11:16:19 -04:00
func Flags () * codersdk . DeploymentFlags {
return & codersdk . DeploymentFlags {
AccessURL : & codersdk . StringFlag {
2022-10-10 15:04:15 -04:00
Name : "Access URL" ,
Flag : "access-url" ,
EnvVar : "CODER_ACCESS_URL" ,
Description : "External URL to access your deployment. This must be accessible by all provisioned workspaces." ,
},
2022-10-11 11:16:19 -04:00
WildcardAccessURL : & codersdk . StringFlag {
2022-10-10 15:04:15 -04:00
Name : "Wildcard Address URL" ,
Flag : "wildcard-access-url" ,
EnvVar : "CODER_WILDCARD_ACCESS_URL" ,
2022-10-15 04:25:11 +10:00
Description : `Specifies the wildcard hostname to use for workspace applications in the form "*.example.com" or "*-suffix.example.com". Ports or schemes should not be included. The scheme will be copied from the access URL.` ,
2022-10-10 15:04:15 -04:00
},
2022-10-11 11:16:19 -04:00
Address : & codersdk . StringFlag {
2022-10-10 15:04:15 -04:00
Name : "Bind Address" ,
Flag : "address" ,
EnvVar : "CODER_ADDRESS" ,
Shorthand : "a" ,
Description : "Bind address of the server." ,
Default : "127.0.0.1:3000" ,
},
2022-10-11 11:16:19 -04:00
AutobuildPollInterval : & codersdk . DurationFlag {
2022-10-10 15:04:15 -04:00
Name : "Autobuild Poll Interval" ,
Flag : "autobuild-poll-interval" ,
EnvVar : "CODER_AUTOBUILD_POLL_INTERVAL" ,
Description : "Interval to poll for scheduled workspace builds." ,
2022-10-11 11:16:19 -04:00
Hidden : true ,
2022-10-10 15:04:15 -04:00
Default : time . Minute ,
},
2022-10-11 11:16:19 -04:00
DerpServerEnable : & codersdk . BoolFlag {
2022-10-10 15:04:15 -04:00
Name : "DERP Server Enabled" ,
Flag : "derp-server-enable" ,
EnvVar : "CODER_DERP_SERVER_ENABLE" ,
Description : "Whether to enable or disable the embedded DERP relay server." ,
Default : true ,
},
2022-10-11 11:16:19 -04:00
DerpServerRegionID : & codersdk . IntFlag {
2022-10-10 15:04:15 -04:00
Name : "DERP Server Region ID" ,
Flag : "derp-server-region-id" ,
EnvVar : "CODER_DERP_SERVER_REGION_ID" ,
Description : "Region ID to use for the embedded DERP server." ,
Default : 999 ,
},
2022-10-11 11:16:19 -04:00
DerpServerRegionCode : & codersdk . StringFlag {
2022-10-10 15:04:15 -04:00
Name : "DERP Server Region Code" ,
Flag : "derp-server-region-code" ,
EnvVar : "CODER_DERP_SERVER_REGION_CODE" ,
Description : "Region code to use for the embedded DERP server." ,
Default : "coder" ,
},
2022-10-11 11:16:19 -04:00
DerpServerRegionName : & codersdk . StringFlag {
2022-10-10 15:04:15 -04:00
Name : "DERP Server Region Name" ,
Flag : "derp-server-region-name" ,
EnvVar : "CODER_DERP_SERVER_REGION_NAME" ,
Description : "Region name that for the embedded DERP server." ,
Default : "Coder Embedded Relay" ,
},
2022-10-11 11:16:19 -04:00
DerpServerSTUNAddresses : & codersdk . StringArrayFlag {
2022-10-10 15:04:15 -04:00
Name : "DERP Server STUN Addresses" ,
Flag : "derp-server-stun-addresses" ,
EnvVar : "CODER_DERP_SERVER_STUN_ADDRESSES" ,
Description : "Addresses for STUN servers to establish P2P connections. Set empty to disable P2P connections." ,
Default : [] string { "stun.l.google.com:19302" },
},
2022-10-17 08:43:30 -05:00
DerpServerRelayAddress : & codersdk . StringFlag {
Name : "DERP Server Relay Address" ,
Flag : "derp-server-relay-address" ,
EnvVar : "CODER_DERP_SERVER_RELAY_ADDRESS" ,
Description : "An HTTP address that is accessible by other replicas to relay DERP traffic. Required for high availability." ,
Enterprise : true ,
},
2022-10-11 11:16:19 -04:00
DerpConfigURL : & codersdk . StringFlag {
2022-10-10 15:04:15 -04:00
Name : "DERP Config URL" ,
Flag : "derp-config-url" ,
EnvVar : "CODER_DERP_CONFIG_URL" ,
Description : "URL to fetch a DERP mapping on startup. See: https://tailscale.com/kb/1118/custom-derp-servers/" ,
},
2022-10-11 11:16:19 -04:00
DerpConfigPath : & codersdk . StringFlag {
2022-10-10 15:04:15 -04:00
Name : "DERP Config Path" ,
Flag : "derp-config-path" ,
EnvVar : "CODER_DERP_CONFIG_PATH" ,
Description : "Path to read a DERP mapping from. See: https://tailscale.com/kb/1118/custom-derp-servers/" ,
},
2022-10-11 11:16:19 -04:00
PromEnabled : & codersdk . BoolFlag {
2022-10-10 15:04:15 -04:00
Name : "Prometheus Enabled" ,
Flag : "prometheus-enable" ,
EnvVar : "CODER_PROMETHEUS_ENABLE" ,
Description : "Serve prometheus metrics on the address defined by `prometheus-address`." ,
},
2022-10-11 11:16:19 -04:00
PromAddress : & codersdk . StringFlag {
2022-10-10 15:04:15 -04:00
Name : "Prometheus Address" ,
Flag : "prometheus-address" ,
EnvVar : "CODER_PROMETHEUS_ADDRESS" ,
Description : "The bind address to serve prometheus metrics." ,
Default : "127.0.0.1:2112" ,
},
2022-10-11 11:16:19 -04:00
PprofEnabled : & codersdk . BoolFlag {
2022-10-10 15:04:15 -04:00
Name : "pprof Enabled" ,
Flag : "pprof-enable" ,
EnvVar : "CODER_PPROF_ENABLE" ,
Description : "Serve pprof metrics on the address defined by `pprof-address`." ,
},
2022-10-11 11:16:19 -04:00
PprofAddress : & codersdk . StringFlag {
2022-10-10 15:04:15 -04:00
Name : "pprof Address" ,
Flag : "pprof-address" ,
EnvVar : "CODER_PPROF_ADDRESS" ,
Description : "The bind address to serve pprof." ,
Default : "127.0.0.1:6060" ,
},
2022-10-11 11:16:19 -04:00
CacheDir : & codersdk . StringFlag {
2022-10-10 15:04:15 -04:00
Name : "Cache Directory" ,
Flag : "cache-dir" ,
EnvVar : "CODER_CACHE_DIRECTORY" ,
Description : "The directory to cache temporary files. If unspecified and $CACHE_DIRECTORY is set, it will be used for compatibility with systemd." ,
Default : defaultCacheDir (),
},
2022-10-11 11:16:19 -04:00
InMemoryDatabase : & codersdk . BoolFlag {
2022-10-10 15:04:15 -04:00
Name : "In-Memory Database" ,
Flag : "in-memory" ,
EnvVar : "CODER_INMEMORY" ,
Description : "Controls whether data will be stored in an in-memory database." ,
2022-10-11 11:16:19 -04:00
Hidden : true ,
2022-10-10 15:04:15 -04:00
},
2022-10-11 11:16:19 -04:00
ProvisionerDaemonCount : & codersdk . IntFlag {
2022-10-10 15:04:15 -04:00
Name : "Provisioner Daemons" ,
Flag : "provisioner-daemons" ,
EnvVar : "CODER_PROVISIONER_DAEMONS" ,
Description : "Number of provisioner daemons to create on start. If builds are stuck in queued state for a long time, consider increasing this." ,
Default : 3 ,
},
2022-10-11 11:16:19 -04:00
PostgresURL : & codersdk . StringFlag {
2022-10-10 15:04:15 -04:00
Name : "Postgres URL" ,
Flag : "postgres-url" ,
EnvVar : "CODER_PG_CONNECTION_URL" ,
Description : "URL of a PostgreSQL database. If empty, PostgreSQL binaries will be downloaded from Maven (https://repo1.maven.org/maven2) and store all data in the config root. Access the built-in database with \"coder server postgres-builtin-url\"" ,
Secret : true ,
},
2022-10-11 11:16:19 -04:00
OAuth2GithubClientID : & codersdk . StringFlag {
2022-10-10 15:04:15 -04:00
Name : "Oauth2 Github Client ID" ,
Flag : "oauth2-github-client-id" ,
EnvVar : "CODER_OAUTH2_GITHUB_CLIENT_ID" ,
Description : "Client ID for Login with GitHub." ,
},
2022-10-11 11:16:19 -04:00
OAuth2GithubClientSecret : & codersdk . StringFlag {
2022-10-10 15:04:15 -04:00
Name : "Oauth2 Github Client Secret" ,
Flag : "oauth2-github-client-secret" ,
EnvVar : "CODER_OAUTH2_GITHUB_CLIENT_SECRET" ,
Description : "Client secret for Login with GitHub." ,
Secret : true ,
},
2022-10-11 11:16:19 -04:00
OAuth2GithubAllowedOrganizations : & codersdk . StringArrayFlag {
2022-10-10 15:04:15 -04:00
Name : "Oauth2 Github Allowed Organizations" ,
Flag : "oauth2-github-allowed-orgs" ,
EnvVar : "CODER_OAUTH2_GITHUB_ALLOWED_ORGS" ,
Description : "Organizations the user must be a member of to Login with GitHub." ,
2022-10-11 11:16:19 -04:00
Default : [] string {},
2022-10-10 15:04:15 -04:00
},
2022-10-11 11:16:19 -04:00
OAuth2GithubAllowedTeams : & codersdk . StringArrayFlag {
2022-10-10 15:04:15 -04:00
Name : "Oauth2 Github Allowed Teams" ,
Flag : "oauth2-github-allowed-teams" ,
EnvVar : "CODER_OAUTH2_GITHUB_ALLOWED_TEAMS" ,
Description : "Teams inside organizations the user must be a member of to Login with GitHub. Structured as: <organization-name>/<team-slug>." ,
2022-10-11 11:16:19 -04:00
Default : [] string {},
2022-10-10 15:04:15 -04:00
},
2022-10-11 11:16:19 -04:00
OAuth2GithubAllowSignups : & codersdk . BoolFlag {
2022-10-10 15:04:15 -04:00
Name : "Oauth2 Github Allow Signups" ,
Flag : "oauth2-github-allow-signups" ,
2022-10-10 16:19:37 -04:00
EnvVar : "CODER_OAUTH2_GITHUB_ALLOW_SIGNUPS" ,
2022-10-10 15:04:15 -04:00
Description : "Whether new users can sign up with GitHub." ,
},
2022-10-11 11:16:19 -04:00
OAuth2GithubEnterpriseBaseURL : & codersdk . StringFlag {
2022-10-10 15:04:15 -04:00
Name : "Oauth2 Github Enterprise Base URL" ,
Flag : "oauth2-github-enterprise-base-url" ,
EnvVar : "CODER_OAUTH2_GITHUB_ENTERPRISE_BASE_URL" ,
Description : "Base URL of a GitHub Enterprise deployment to use for Login with GitHub." ,
},
2022-10-11 11:16:19 -04:00
OIDCAllowSignups : & codersdk . BoolFlag {
2022-10-10 15:04:15 -04:00
Name : "OIDC Allow Signups" ,
Flag : "oidc-allow-signups" ,
EnvVar : "CODER_OIDC_ALLOW_SIGNUPS" ,
Description : "Whether new users can sign up with OIDC." ,
Default : true ,
},
2022-10-11 11:16:19 -04:00
OIDCClientID : & codersdk . StringFlag {
2022-10-10 15:04:15 -04:00
Name : "OIDC Client ID" ,
Flag : "oidc-client-id" ,
EnvVar : "CODER_OIDC_CLIENT_ID" ,
Description : "Client ID to use for Login with OIDC." ,
},
2022-10-11 11:16:19 -04:00
OIDCClientSecret : & codersdk . StringFlag {
2022-10-10 15:04:15 -04:00
Name : "OIDC Client Secret" ,
Flag : "oidc-client-secret" ,
EnvVar : "CODER_OIDC_CLIENT_SECRET" ,
Description : "Client secret to use for Login with OIDC." ,
Secret : true ,
},
2022-10-11 11:16:19 -04:00
OIDCEmailDomain : & codersdk . StringFlag {
2022-10-10 15:04:15 -04:00
Name : "OIDC Email Domain" ,
Flag : "oidc-email-domain" ,
EnvVar : "CODER_OIDC_EMAIL_DOMAIN" ,
Description : "Email domain that clients logging in with OIDC must match." ,
},
2022-10-11 11:16:19 -04:00
OIDCIssuerURL : & codersdk . StringFlag {
2022-10-10 15:04:15 -04:00
Name : "OIDC Issuer URL" ,
Flag : "oidc-issuer-url" ,
EnvVar : "CODER_OIDC_ISSUER_URL" ,
Description : "Issuer URL to use for Login with OIDC." ,
},
2022-10-11 11:16:19 -04:00
OIDCScopes : & codersdk . StringArrayFlag {
2022-10-10 15:04:15 -04:00
Name : "OIDC Scopes" ,
Flag : "oidc-scopes" ,
EnvVar : "CODER_OIDC_SCOPES" ,
Description : "Scopes to grant when authenticating with OIDC." ,
Default : [] string { oidc . ScopeOpenID , "profile" , "email" },
},
2022-10-11 11:16:19 -04:00
TelemetryEnable : & codersdk . BoolFlag {
2022-10-10 15:04:15 -04:00
Name : "Telemetry Enabled" ,
Flag : "telemetry" ,
EnvVar : "CODER_TELEMETRY" ,
Description : "Whether telemetry is enabled or not. Coder collects anonymized usage data to help improve our product." ,
Default : flag . Lookup ( "test.v" ) == nil ,
},
2022-10-11 11:16:19 -04:00
TelemetryTraceEnable : & codersdk . BoolFlag {
2022-10-10 15:04:15 -04:00
Name : "Trace Telemetry Enabled" ,
Flag : "telemetry-trace" ,
EnvVar : "CODER_TELEMETRY_TRACE" ,
Shorthand : "" ,
Description : "Whether Opentelemetry traces are sent to Coder. Coder collects anonymized application tracing to help improve our product. Disabling telemetry also disables this option." ,
Default : flag . Lookup ( "test.v" ) == nil ,
},
2022-10-11 11:16:19 -04:00
TelemetryURL : & codersdk . StringFlag {
2022-10-10 15:04:15 -04:00
Name : "Telemetry URL" ,
Flag : "telemetry-url" ,
EnvVar : "CODER_TELEMETRY_URL" ,
Description : "URL to send telemetry." ,
2022-10-11 11:16:19 -04:00
Hidden : true ,
2022-10-10 15:04:15 -04:00
Default : "https://telemetry.coder.com" ,
},
2022-10-11 11:16:19 -04:00
TLSEnable : & codersdk . BoolFlag {
2022-10-10 15:04:15 -04:00
Name : "TLS Enabled" ,
Flag : "tls-enable" ,
EnvVar : "CODER_TLS_ENABLE" ,
Description : "Whether TLS will be enabled." ,
},
2022-10-11 11:16:19 -04:00
TLSCertFiles : & codersdk . StringArrayFlag {
2022-10-10 15:04:15 -04:00
Name : "TLS Cert Files" ,
Flag : "tls-cert-file" ,
EnvVar : "CODER_TLS_CERT_FILE" ,
Description : "Path to each certificate for TLS. It requires a PEM-encoded file. " +
"To configure the listener to use a CA certificate, concatenate the primary certificate " +
"and the CA certificate together. The primary certificate should appear first in the combined file." ,
Default : [] string {},
},
2022-10-11 11:16:19 -04:00
TLSClientCAFile : & codersdk . StringFlag {
2022-10-10 15:04:15 -04:00
Name : "TLS Client CA File" ,
Flag : "tls-client-ca-file" ,
EnvVar : "CODER_TLS_CLIENT_CA_FILE" ,
Description : "PEM-encoded Certificate Authority file used for checking the authenticity of client" ,
},
2022-10-11 11:16:19 -04:00
TLSClientAuth : & codersdk . StringFlag {
2022-10-10 15:04:15 -04:00
Name : "TLS Client Auth" ,
Flag : "tls-client-auth" ,
2022-10-10 15:26:27 -04:00
EnvVar : "CODER_TLS_CLIENT_AUTH" ,
2022-10-10 15:04:15 -04:00
Description : `Policy the server will follow for TLS Client Authentication. ` +
`Accepted values are "none", "request", "require-any", "verify-if-given", or "require-and-verify"` ,
Default : "request" ,
},
2022-10-11 11:16:19 -04:00
TLSKeyFiles : & codersdk . StringArrayFlag {
2022-10-10 15:04:15 -04:00
Name : "TLS Key Files" ,
Flag : "tls-key-file" ,
EnvVar : "CODER_TLS_KEY_FILE" ,
Description : "Paths to the private keys for each of the certificates. It requires a PEM-encoded file" ,
Default : [] string {},
},
2022-10-11 11:16:19 -04:00
TLSMinVersion : & codersdk . StringFlag {
2022-10-10 15:04:15 -04:00
Name : "TLS Min Version" ,
Flag : "tls-min-version" ,
EnvVar : "CODER_TLS_MIN_VERSION" ,
Description : `Minimum supported version of TLS. Accepted values are "tls10", "tls11", "tls12" or "tls13"` ,
Default : "tls12" ,
},
2022-10-11 11:16:19 -04:00
TraceEnable : & codersdk . BoolFlag {
2022-10-10 15:04:15 -04:00
Name : "Trace Enabled" ,
Flag : "trace" ,
EnvVar : "CODER_TRACE" ,
Description : "Whether application tracing data is collected." ,
},
2022-10-11 11:16:19 -04:00
SecureAuthCookie : & codersdk . BoolFlag {
2022-10-10 15:04:15 -04:00
Name : "Secure Auth Cookie" ,
Flag : "secure-auth-cookie" ,
EnvVar : "CODER_SECURE_AUTH_COOKIE" ,
Description : "Controls if the 'Secure' property is set on browser session cookies" ,
},
2022-10-11 11:16:19 -04:00
SSHKeygenAlgorithm : & codersdk . StringFlag {
2022-10-10 15:04:15 -04:00
Name : "SSH Keygen Algorithm" ,
Flag : "ssh-keygen-algorithm" ,
EnvVar : "CODER_SSH_KEYGEN_ALGORITHM" ,
Description : "The algorithm to use for generating ssh keys. " +
`Accepted values are "ed25519", "ecdsa", or "rsa4096"` ,
Default : "ed25519" ,
},
2022-10-11 11:16:19 -04:00
AutoImportTemplates : & codersdk . StringArrayFlag {
2022-10-10 15:04:15 -04:00
Name : "Auto Import Templates" ,
Flag : "auto-import-template" ,
EnvVar : "CODER_TEMPLATE_AUTOIMPORT" ,
Description : "Templates to auto-import. Available auto-importable templates are: kubernetes" ,
2022-10-11 11:16:19 -04:00
Hidden : true ,
2022-10-10 15:04:15 -04:00
Default : [] string {},
},
2022-10-11 11:16:19 -04:00
MetricsCacheRefreshInterval : & codersdk . DurationFlag {
2022-10-10 15:04:15 -04:00
Name : "Metrics Cache Refresh Interval" ,
Flag : "metrics-cache-refresh-interval" ,
EnvVar : "CODER_METRICS_CACHE_REFRESH_INTERVAL" ,
Description : "How frequently metrics are refreshed" ,
2022-10-11 11:16:19 -04:00
Hidden : true ,
2022-10-10 15:04:15 -04:00
Default : time . Hour ,
},
2022-10-11 11:16:19 -04:00
AgentStatRefreshInterval : & codersdk . DurationFlag {
2022-10-10 15:04:15 -04:00
Name : "Agent Stats Refresh Interval" ,
Flag : "agent-stats-refresh-interval" ,
EnvVar : "CODER_AGENT_STATS_REFRESH_INTERVAL" ,
Description : "How frequently agent stats are recorded" ,
2022-10-11 11:16:19 -04:00
Hidden : true ,
2022-10-10 15:04:15 -04:00
Default : 10 * time . Minute ,
},
2022-10-11 11:16:19 -04:00
Verbose : & codersdk . BoolFlag {
2022-10-10 15:04:15 -04:00
Name : "Verbose Logging" ,
Flag : "verbose" ,
EnvVar : "CODER_VERBOSE" ,
Shorthand : "v" ,
Description : "Enables verbose logging." ,
},
2022-10-11 11:16:19 -04:00
AuditLogging : & codersdk . BoolFlag {
2022-10-10 15:04:15 -04:00
Name : "Audit Logging" ,
Flag : "audit-logging" ,
EnvVar : "CODER_AUDIT_LOGGING" ,
Description : "Specifies whether audit logging is enabled." ,
Default : true ,
Enterprise : true ,
},
2022-10-11 11:16:19 -04:00
BrowserOnly : & codersdk . BoolFlag {
2022-10-10 15:04:15 -04:00
Name : "Browser Only" ,
Flag : "browser-only" ,
EnvVar : "CODER_BROWSER_ONLY" ,
Description : "Whether Coder only allows connections to workspaces via the browser." ,
Enterprise : true ,
},
2022-10-11 11:16:19 -04:00
SCIMAuthHeader : & codersdk . StringFlag {
2022-10-10 15:04:15 -04:00
Name : "SCIM Authentication Header" ,
Flag : "scim-auth-header" ,
EnvVar : "CODER_SCIM_API_KEY" ,
Description : "Enables SCIM and sets the authentication header for the built-in SCIM server. New users are automatically created with OIDC authentication." ,
Secret : true ,
Enterprise : true ,
},
2022-10-11 11:16:19 -04:00
UserWorkspaceQuota : & codersdk . IntFlag {
2022-10-10 15:04:15 -04:00
Name : "User Workspace Quota" ,
Flag : "user-workspace-quota" ,
EnvVar : "CODER_USER_WORKSPACE_QUOTA" ,
Description : "Enables and sets a limit on how many workspaces each user can create." ,
Default : 0 ,
Enterprise : true ,
},
}
}
func RemoveSensitiveValues ( df codersdk . DeploymentFlags ) codersdk . DeploymentFlags {
v := reflect . ValueOf ( & df ). Elem ()
t := v . Type ()
for i := 0 ; i < t . NumField (); i ++ {
fv := v . Field ( i )
2022-10-11 11:16:19 -04:00
if vp , ok := fv . Interface ().( * codersdk . StringFlag ); ok {
if vp . Secret && vp . Value != "" {
// Make a copy and remove the value.
v := * vp
2022-10-10 15:04:15 -04:00
v . Value = secretValue
2022-10-11 11:16:19 -04:00
fv . Set ( reflect . ValueOf ( & v ))
2022-10-10 15:04:15 -04:00
}
}
}
return df
}
2022-10-11 11:16:19 -04:00
//nolint:revive
func AttachFlags ( flagset * pflag . FlagSet , df * codersdk . DeploymentFlags , enterprise bool ) {
v := reflect . ValueOf ( df ). Elem ()
t := v . Type ()
for i := 0 ; i < t . NumField (); i ++ {
fv := v . Field ( i )
fve := fv . Elem ()
e := fve . FieldByName ( "Enterprise" ). Bool ()
if e != enterprise {
continue
}
if e {
d := fve . FieldByName ( "Description" ). String ()
d += cliui . Styles . Keyword . Render ( " This is an Enterprise feature. Contact sales@coder.com for licensing" )
fve . FieldByName ( "Description" ). SetString ( d )
}
switch v := fv . Interface ().( type ) {
case * codersdk . StringFlag :
StringFlag ( flagset , v )
case * codersdk . StringArrayFlag :
StringArrayFlag ( flagset , v )
case * codersdk . IntFlag :
IntFlag ( flagset , v )
case * codersdk . BoolFlag :
BoolFlag ( flagset , v )
case * codersdk . DurationFlag :
DurationFlag ( flagset , v )
default :
panic ( fmt . Sprintf ( "unknown flag type: %T" , v ))
}
if fve . FieldByName ( "Hidden" ). Bool () {
_ = flagset . MarkHidden ( fve . FieldByName ( "Flag" ). String ())
}
}
}
2022-10-10 15:04:15 -04:00
func StringFlag ( flagset * pflag . FlagSet , fl * codersdk . StringFlag ) {
cliflag . StringVarP ( flagset ,
& fl . Value ,
fl . Flag ,
fl . Shorthand ,
fl . EnvVar ,
fl . Default ,
fl . Description ,
)
}
func BoolFlag ( flagset * pflag . FlagSet , fl * codersdk . BoolFlag ) {
cliflag . BoolVarP ( flagset ,
& fl . Value ,
fl . Flag ,
fl . Shorthand ,
fl . EnvVar ,
fl . Default ,
fl . Description ,
)
}
func IntFlag ( flagset * pflag . FlagSet , fl * codersdk . IntFlag ) {
cliflag . IntVarP ( flagset ,
& fl . Value ,
fl . Flag ,
fl . Shorthand ,
fl . EnvVar ,
fl . Default ,
fl . Description ,
)
}
func DurationFlag ( flagset * pflag . FlagSet , fl * codersdk . DurationFlag ) {
cliflag . DurationVarP ( flagset ,
& fl . Value ,
fl . Flag ,
fl . Shorthand ,
fl . EnvVar ,
fl . Default ,
fl . Description ,
)
}
func StringArrayFlag ( flagset * pflag . FlagSet , fl * codersdk . StringArrayFlag ) {
cliflag . StringArrayVarP ( flagset ,
& fl . Value ,
fl . Flag ,
fl . Shorthand ,
fl . EnvVar ,
fl . Default ,
fl . Description ,
)
}
func defaultCacheDir () string {
defaultCacheDir , err := os . UserCacheDir ()
if err != nil {
defaultCacheDir = os . TempDir ()
}
if dir := os . Getenv ( "CACHE_DIRECTORY" ); dir != "" {
// For compatibility with systemd.
defaultCacheDir = dir
}
return filepath . Join ( defaultCacheDir , "coder" )
}