From 1297b8b2a84116faed41dc1fad2f3bda464b0454 Mon Sep 17 00:00:00 2001 From: Volker Schukai <volker.schukai@schukai.com> Date: Sat, 5 Aug 2023 19:24:41 +0200 Subject: [PATCH] chore: Refactor configuration setup and command execution - Remove commented out code and unused code related to settings, configuration change event handling, and message and config endpoints - Fix bug where error messages are not printed when there are configuration errors and verbose mode is disabled - Update vendorSha256, ldflags, buildInputs, and description for the docman package in flake.nix - Remove Database struct and add Verbose field to AppConfig struct in source/config/definition.go - Refactor TestMaskCodeBlocks function in source/utils/strings_test.go - Modify SetUp function in source/config/setup.go - Update ConfigPath and remove Release command in CommandsStruct struct in source/command/definition.go - Change variable assignment and add error handling, command line argument parsing, setup of configuration, and execution of commands in source/command/execute.go - Add version parameter and disable DIRENV_ENABLED and DIRENV_TRUSTED in .idea/runConfigurations/go_build_gitlab_schukai_com_oss_utilities_documentation_manager.xml --- ...om_oss_utilities_documentation_manager.xml | 1 + flake.nix | 8 +-- source/command/definition.go | 18 +++++- source/command/execute.go | 2 +- source/config/constraints.go | 63 ------------------- source/config/definition.go | 5 +- source/config/setup.go | 2 +- source/main.go | 4 -- source/utils/strings_test.go | 4 -- 9 files changed, 22 insertions(+), 85 deletions(-) diff --git a/.idea/runConfigurations/go_build_gitlab_schukai_com_oss_utilities_documentation_manager.xml b/.idea/runConfigurations/go_build_gitlab_schukai_com_oss_utilities_documentation_manager.xml index cd1de85..4a46a10 100644 --- a/.idea/runConfigurations/go_build_gitlab_schukai_com_oss_utilities_documentation_manager.xml +++ b/.idea/runConfigurations/go_build_gitlab_schukai_com_oss_utilities_documentation_manager.xml @@ -2,6 +2,7 @@ <configuration default="false" name="go build gitlab.schukai.com/oss/utilities/documentation-manager" type="GoApplicationRunConfiguration" factoryName="Go Application" nameIsGenerated="true"> <module name="documentation-manager" /> <working_directory value="$PROJECT_DIR$/" /> + <parameters value="version" /> <EXTENSION ID="com.fapiko.jetbrains.plugins.better_direnv.runconfigs.GolandRunConfigurationExtension"> <option name="DIRENV_ENABLED" value="false" /> <option name="DIRENV_TRUSTED" value="false" /> diff --git a/flake.nix b/flake.nix index eb967c9..fd7e322 100644 --- a/flake.nix +++ b/flake.nix @@ -63,13 +63,9 @@ #vendorSha256 = "sha256-XdB+u94Rqsb29jVs4miyOq1NEYaVJHWFXg6QebFJzNQ="; vendorSha256 = "sha256-81IBG8H1jsYKD+tmFeCpAWFdz6cuQDt9r+FV56xboBU="; - # "-X release.version=$version -X release.build=$(due --iso-8601 | tr -d "-" )" - ldflags = [ - "-s" - "-w" - "-X release.version=1" - "-X release.build=2" + "-X release.version=${version}" + "-X release.build=${build}" ]; buildInputs = [ versionTool.defaultPackage.${system} ]; diff --git a/source/command/definition.go b/source/command/definition.go index c3d008e..6813fdd 100644 --- a/source/command/definition.go +++ b/source/command/definition.go @@ -1,6 +1,20 @@ package command type CommandsStruct struct { - ConfigPath string `long:"config" short:"c" description:"Path to configuration file"` - Release ReleaseCommand `command:"release" description:"Release commands"` + ConfigPath string `long:"config" short:"c" description:"Path to configuration file"` + Verbose bool `long:"verbose" short:"v" description:"Verbose output"` + Version struct { + } `command:"version" description:"Prints the version" call:"PrintReleaseInfo"` } + +// +//type Definition struct { +// Verbose bool `short:"v" long:"verbose" description:"Show verbose debug information"` +// ConfigurationPath string `short:"c" long:"config" description:"Path to the configuration file"` +// Version struct { +// } `command:"version" description:"Prints the version" call:"PrintVersion"` +// Document struct { +// } `command:"document" description:"Document related commands"` +// Server struct { +// } `command:"server" description:"Server related commands"` +//} diff --git a/source/command/execute.go b/source/command/execute.go index 1bd832e..ec056b2 100644 --- a/source/command/execute.go +++ b/source/command/execute.go @@ -16,7 +16,7 @@ var helpInfo = "\nYou can use the --help flag to get more information about the func Execute() { - instance := xflags.New(os.Args[0], CommandsStruct{}) + instance = xflags.New(os.Args[0], CommandsStruct{}) if instance.HasErrors() { for _, msg := range instance.Errors() { error2.PrintError(msg.Error()) diff --git a/source/config/constraints.go b/source/config/constraints.go index 249c581..8a2fc65 100644 --- a/source/config/constraints.go +++ b/source/config/constraints.go @@ -3,66 +3,3 @@ package config func checkConstraints() bool { return true } - -// func sanitizeMessageEndpoint() { -// //e := Instance.Client.Endpoints.Messages -// // -// //u, err := url.ParseRequestURI(e) -// //error2.CheckError(err) -// // -// //if u.Scheme != "ws" { -// // u.Scheme = "ws" -// //} -// // -// //if u.Host == "" { -// // u.Host = Instance.Server.Host -// // if u.Host == "" { -// // error2.PrintErrorAndExit("Invalid message endpoint: " + e) -// // } -// //} -// // -// //Instance.Client.Endpoints.Messages = u.String() -// -// } -// -// func sanitizeConfigEndpoint() { -// //e := Instance.Client.Endpoints.Config -// // -// //u, err := url.ParseRequestURI(e) -// //error2.CheckError(err) -// // -// //if u.Scheme != "http" { -// // u.Scheme = "http" -// //} -// // -// //if u.Host == "" { -// // u.Host = Instance.Server.Host -// // if u.Host == "" { -// // error2.PrintErrorAndExit("Invalid config endpoint: " + e) -// // } -// //} -// // -// //Instance.Client.Endpoints.Config = u.String() -// -// cfg := Instance.Config() -// -// e := cfg.Client.Endpoints.Config -// -// u, err := url.ParseRequestURI(e) -// error2.CheckError(err) -// -// if strings.HasPrefix(u.Scheme, "http") { -// u.Scheme = "http" -// } -// -// if u.Host == "" { -// u.Host = cfg.Server.Host -// if u.Host == "" { -// error2.PrintErrorAndExit("Invalid message endpoint: " + e) -// } -// } -// -// cfg.Client.Endpoints.Config = u.String() -// Instance.SetConfig(cfg) -// -// } diff --git a/source/config/definition.go b/source/config/definition.go index a372609..b548091 100644 --- a/source/config/definition.go +++ b/source/config/definition.go @@ -3,8 +3,5 @@ package config type Settings map[string]interface{} type AppConfig struct { - Database struct { - // user:pass@tcp(127.0.0.1:3306)/alvine_platform?charset=utf8mb4&parseTime=True&loc=Local - DSN string `env:"DATABASE_DSN" yaml:"DSN"` - } `yaml:"Database"` + Verbose bool `env:"DATABASE_DSN" yaml:"DSN"` } diff --git a/source/config/setup.go b/source/config/setup.go index ea48e22..f9bdf3f 100644 --- a/source/config/setup.go +++ b/source/config/setup.go @@ -58,7 +58,7 @@ func SetUp(cfgPath string) { //preparation.OnChange(once) preparation.Import() - if preparation.HasErrors() { + if preparation.HasErrors() && Instance.Config().Verbose { for _, msg := range preparation.Errors() { error2.PrintError(msg.Error()) } diff --git a/source/main.go b/source/main.go index c15195e..0a9d19b 100644 --- a/source/main.go +++ b/source/main.go @@ -4,10 +4,6 @@ package main import "gitlab.schukai.com/oss/utilities/documentation-manager/command" -//var ( -// settings *xflags.Settings[commands.Definition] -//) - func main() { command.Execute() diff --git a/source/utils/strings_test.go b/source/utils/strings_test.go index e2e09f0..600aa67 100644 --- a/source/utils/strings_test.go +++ b/source/utils/strings_test.go @@ -23,11 +23,7 @@ func TestMaskCodeBlocks(t *testing.T) { for _, table := range tables { - //p, _ := os.Getwd() _, p, _, _ := runtime.Caller(0) - // p = filepath.Dir(p) // go to parent directory - //p = filepath.Dir(p) // go to parent directory - //p = filepath.Dir(p) // go to parent directory p = filepath.Dir(p) // go to parent directory p = filepath.Join(p, table.input) -- GitLab