diff options
author | 2021-12-07 13:31:39 +0100 | |
---|---|---|
committer | 2021-12-07 13:31:39 +0100 | |
commit | 0884f89431cd26bcc9674b3b7ab628b090f5881e (patch) | |
tree | cdd3b3f77f780a8b59d075dbcc3d4d013811e405 /cmd/gotosocial/flag/server.go | |
parent | Update dependencies (#333) (diff) | |
download | gotosocial-0884f89431cd26bcc9674b3b7ab628b090f5881e.tar.xz |
Implement Cobra CLI tooling, Viper config tooling (#336)
* start pulling out + replacing urfave and config
* replace many many instances of config
* move more stuff => viper
* properly remove urfave
* move some flags to root command
* add testrig commands to root
* alias config file keys
* start adding cli parsing tests
* reorder viper init
* remove config path alias
* fmt
* change config file keys to non-nested
* we're more or less in business now
* tidy up the common func
* go fmt
* get tests passing again
* add note about the cliparsing tests
* reorganize
* update docs with changes
* structure cmd dir better
* rename + move some files around
* fix dangling comma
Diffstat (limited to 'cmd/gotosocial/flag/server.go')
-rw-r--r-- | cmd/gotosocial/flag/server.go | 111 |
1 files changed, 111 insertions, 0 deletions
diff --git a/cmd/gotosocial/flag/server.go b/cmd/gotosocial/flag/server.go new file mode 100644 index 000000000..3d3e946f3 --- /dev/null +++ b/cmd/gotosocial/flag/server.go @@ -0,0 +1,111 @@ +/* + GoToSocial + Copyright (C) 2021 GoToSocial Authors admin@gotosocial.org + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU Affero General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU Affero General Public License for more details. + + You should have received a copy of the GNU Affero General Public License + along with this program. If not, see <http://www.gnu.org/licenses/>. +*/ + +package flag + +import ( + "github.com/spf13/cobra" + "github.com/superseriousbusiness/gotosocial/internal/config" +) + +// Server attaches all flags pertaining to running the GtS server or testrig. +func Server(cmd *cobra.Command, values config.Values) { + Template(cmd, values) + Accounts(cmd, values) + Media(cmd, values) + Storage(cmd, values) + Statuses(cmd, values) + LetsEncrypt(cmd, values) + OIDC(cmd, values) + SMTP(cmd, values) + Router(cmd, values) +} + +// Router attaches flags pertaining to the gin router. +func Router(cmd *cobra.Command, values config.Values) { + cmd.PersistentFlags().String(config.Keys.BindAddress, values.BindAddress, usage.BindAddress) + cmd.PersistentFlags().Int(config.Keys.Port, values.Port, usage.Port) + cmd.PersistentFlags().StringSlice(config.Keys.TrustedProxies, values.TrustedProxies, usage.TrustedProxies) +} + +// Template attaches flags pertaining to templating config. +func Template(cmd *cobra.Command, values config.Values) { + cmd.Flags().String(config.Keys.WebTemplateBaseDir, values.WebTemplateBaseDir, usage.WebTemplateBaseDir) + cmd.Flags().String(config.Keys.WebAssetBaseDir, values.WebAssetBaseDir, usage.WebAssetBaseDir) +} + +// Accounts attaches flags pertaining to account config. +func Accounts(cmd *cobra.Command, values config.Values) { + cmd.Flags().Bool(config.Keys.AccountsRegistrationOpen, values.AccountsRegistrationOpen, usage.AccountsRegistrationOpen) + cmd.Flags().Bool(config.Keys.AccountsApprovalRequired, values.AccountsApprovalRequired, usage.AccountsApprovalRequired) + cmd.Flags().Bool(config.Keys.AccountsReasonRequired, values.AccountsReasonRequired, usage.AccountsReasonRequired) +} + +// Media attaches flags pertaining to media config. +func Media(cmd *cobra.Command, values config.Values) { + cmd.Flags().Int(config.Keys.MediaImageMaxSize, values.MediaImageMaxSize, usage.MediaImageMaxSize) + cmd.Flags().Int(config.Keys.MediaVideoMaxSize, values.MediaVideoMaxSize, usage.MediaVideoMaxSize) + cmd.Flags().Int(config.Keys.MediaDescriptionMinChars, values.MediaDescriptionMinChars, usage.MediaDescriptionMinChars) + cmd.Flags().Int(config.Keys.MediaDescriptionMaxChars, values.MediaDescriptionMaxChars, usage.MediaDescriptionMaxChars) +} + +// Storage attaches flags pertaining to storage config. +func Storage(cmd *cobra.Command, values config.Values) { + cmd.Flags().String(config.Keys.StorageBackend, values.StorageBackend, usage.StorageBackend) + cmd.Flags().String(config.Keys.StorageBasePath, values.StorageBasePath, usage.StorageBasePath) + cmd.Flags().String(config.Keys.StorageServeProtocol, values.StorageServeProtocol, usage.StorageServeProtocol) + cmd.Flags().String(config.Keys.StorageServeHost, values.StorageServeHost, usage.StorageServeHost) + cmd.Flags().String(config.Keys.StorageServeBasePath, values.StorageServeBasePath, usage.StorageServeBasePath) +} + +// Statuses attaches flags pertaining to statuses config. +func Statuses(cmd *cobra.Command, values config.Values) { + cmd.Flags().Int(config.Keys.StatusesMaxChars, values.StatusesMaxChars, usage.StatusesMaxChars) + cmd.Flags().Int(config.Keys.StatusesCWMaxChars, values.StatusesCWMaxChars, usage.StatusesCWMaxChars) + cmd.Flags().Int(config.Keys.StatusesPollMaxOptions, values.StatusesPollMaxOptions, usage.StatusesPollMaxOptions) + cmd.Flags().Int(config.Keys.StatusesPollOptionMaxChars, values.StatusesPollOptionMaxChars, usage.StatusesPollOptionMaxChars) + cmd.Flags().Int(config.Keys.StatusesMediaMaxFiles, values.StatusesMediaMaxFiles, usage.StatusesMediaMaxFiles) +} + +// LetsEncrypt attaches flags pertaining to letsencrypt config. +func LetsEncrypt(cmd *cobra.Command, values config.Values) { + cmd.Flags().Bool(config.Keys.LetsEncryptEnabled, values.LetsEncryptEnabled, usage.LetsEncryptEnabled) + cmd.Flags().Int(config.Keys.LetsEncryptPort, values.LetsEncryptPort, usage.LetsEncryptPort) + cmd.Flags().String(config.Keys.LetsEncryptCertDir, values.LetsEncryptCertDir, usage.LetsEncryptCertDir) + cmd.Flags().String(config.Keys.LetsEncryptEmailAddress, values.LetsEncryptEmailAddress, usage.LetsEncryptEmailAddress) +} + +// OIDC attaches flags pertaining to oidc config. +func OIDC(cmd *cobra.Command, values config.Values) { + cmd.Flags().Bool(config.Keys.OIDCEnabled, values.OIDCEnabled, usage.OIDCEnabled) + cmd.Flags().String(config.Keys.OIDCIdpName, values.OIDCIdpName, usage.OIDCIdpName) + cmd.Flags().Bool(config.Keys.OIDCSkipVerification, values.OIDCSkipVerification, usage.OIDCSkipVerification) + cmd.Flags().String(config.Keys.OIDCIssuer, values.OIDCIssuer, usage.OIDCIssuer) + cmd.Flags().String(config.Keys.OIDCClientID, values.OIDCClientID, usage.OIDCClientID) + cmd.Flags().String(config.Keys.OIDCClientSecret, values.OIDCClientSecret, usage.OIDCClientSecret) + cmd.Flags().StringSlice(config.Keys.OIDCScopes, values.OIDCScopes, usage.OIDCScopes) +} + +// SMTP attaches flags pertaining to smtp/email config. +func SMTP(cmd *cobra.Command, values config.Values) { + cmd.Flags().String(config.Keys.SMTPHost, values.SMTPHost, usage.SMTPHost) + cmd.Flags().Int(config.Keys.SMTPPort, values.SMTPPort, usage.SMTPPort) + cmd.Flags().String(config.Keys.SMTPUsername, values.SMTPUsername, usage.SMTPUsername) + cmd.Flags().String(config.Keys.SMTPPassword, values.SMTPPassword, usage.SMTPPassword) + cmd.Flags().String(config.Keys.SMTPFrom, values.SMTPFrom, usage.SMTPFrom) +} |