From 9877bd2007748b320170358be298205cc860cc90 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jan=20H=C3=A1jek?= Date: Sat, 16 Mar 2024 16:17:36 +0100 Subject: [PATCH] fix: fix permissions (#133) * fix: fix permissions * print help --------- Co-authored-by: jan.hajek@zerops.io --- src/cmd/root.go | 6 ++++++ src/cmdBuilder/createRunFunc.go | 6 ++++++ src/constants/zerops.go | 2 +- src/logger/hooks.go | 2 +- 4 files changed, 14 insertions(+), 2 deletions(-) diff --git a/src/cmd/root.go b/src/cmd/root.go index 6581dbae..bd7b87c5 100644 --- a/src/cmd/root.go +++ b/src/cmd/root.go @@ -43,6 +43,9 @@ func rootCmd() *cmdBuilder.Cmd { cmdData.UxBlocks.Table(body) + // print the default command help + cmdData.PrintHelp() + return nil }). LoggedUserRunFunc(func(ctx context.Context, cmdData *cmdBuilder.LoggedUserCmdData) error { @@ -92,6 +95,9 @@ func rootCmd() *cmdBuilder.Cmd { cmdData.UxBlocks.Table(body) + // print the default command help + cmdData.PrintHelp() + return nil }) } diff --git a/src/cmdBuilder/createRunFunc.go b/src/cmdBuilder/createRunFunc.go index 0d053d1b..0a591c7e 100644 --- a/src/cmdBuilder/createRunFunc.go +++ b/src/cmdBuilder/createRunFunc.go @@ -50,6 +50,8 @@ type GuestCmdData struct { UxBlocks uxBlock.UxBlocks Args map[string][]string Params ParamsReader + + PrintHelp func() } type LoggedUserCmdData struct { @@ -86,6 +88,10 @@ func createCmdRunFunc( UxBlocks: uxBlocks, Args: argsMap, Params: newCmdParamReader(cobraCmd, flagParams), + + PrintHelp: func() { + cobraCmd.HelpFunc()(cobraCmd, []string{}) + }, } storedData := cliStorage.Data() diff --git a/src/constants/zerops.go b/src/constants/zerops.go index bd877510..e4049451 100644 --- a/src/constants/zerops.go +++ b/src/constants/zerops.go @@ -95,7 +95,7 @@ func checkPath(filePath string) (string, error) { return "", err } - f, err := os.OpenFile(filePath, os.O_RDONLY|os.O_CREATE, 0666) + f, err := os.OpenFile(filePath, os.O_APPEND|os.O_CREATE|os.O_RDWR, 0666) if err != nil { return "", err } diff --git a/src/logger/hooks.go b/src/logger/hooks.go index e2bb39ce..a948f749 100644 --- a/src/logger/hooks.go +++ b/src/logger/hooks.go @@ -31,7 +31,7 @@ func (hook *VarLogHook) Fire(entry *logrus.Entry) error { return err } - f, err := os.OpenFile(hook.path, os.O_APPEND|os.O_CREATE|os.O_WRONLY, 0775) + f, err := os.OpenFile(hook.path, os.O_APPEND|os.O_CREATE|os.O_WRONLY, 0666) if err != nil { fmt.Fprintf(os.Stderr, "Unable to open file, %v", err) return err