From 0ca1d4798bd0d5182e8816e5863200471e615363 Mon Sep 17 00:00:00 2001 From: Mohammad Hasan Saeedkia <170322053+MHSaeedkia@users.noreply.github.com> Date: Sat, 11 Jan 2025 20:44:05 +0330 Subject: [PATCH 1/6] ADD about command . --- cmd/discord/main.go | 2 +- cmd/grpc/main.go | 2 +- cmd/http/main.go | 2 +- cmd/telegram/main.go | 2 +- internal/engine/command/command.go | 24 ++++++++++++++++++++++++ internal/engine/engine.go | 1 + 6 files changed, 29 insertions(+), 4 deletions(-) diff --git a/cmd/discord/main.go b/cmd/discord/main.go index 165316ae..0288df7c 100644 --- a/cmd/discord/main.go +++ b/cmd/discord/main.go @@ -1,8 +1,8 @@ package main import ( - "github.com/pagu-project/pagu" "github.com/pagu-project/pagu/cmd" + pagu "github.com/pagu-project/pagu/internal/version" "github.com/spf13/cobra" ) diff --git a/cmd/grpc/main.go b/cmd/grpc/main.go index e41167e1..cf359636 100644 --- a/cmd/grpc/main.go +++ b/cmd/grpc/main.go @@ -1,8 +1,8 @@ package main import ( - "github.com/pagu-project/pagu" "github.com/pagu-project/pagu/cmd" + pagu "github.com/pagu-project/pagu/internal/version" "github.com/spf13/cobra" ) diff --git a/cmd/http/main.go b/cmd/http/main.go index a999fa49..3de359cb 100644 --- a/cmd/http/main.go +++ b/cmd/http/main.go @@ -1,8 +1,8 @@ package main import ( - "github.com/pagu-project/pagu" "github.com/pagu-project/pagu/cmd" + pagu "github.com/pagu-project/pagu/internal/version" "github.com/spf13/cobra" ) diff --git a/cmd/telegram/main.go b/cmd/telegram/main.go index 1f8d539f..8cece160 100644 --- a/cmd/telegram/main.go +++ b/cmd/telegram/main.go @@ -1,8 +1,8 @@ package main import ( - "github.com/pagu-project/pagu" "github.com/pagu-project/pagu/cmd" + pagu "github.com/pagu-project/pagu/internal/version" "github.com/spf13/cobra" ) diff --git a/internal/engine/command/command.go b/internal/engine/command/command.go index b4b716a0..833186aa 100644 --- a/internal/engine/command/command.go +++ b/internal/engine/command/command.go @@ -235,6 +235,16 @@ func (cmd *Command) HelpMessage() string { return help } +func (cmd *Command) AboutMessage() string { + help := cmd.Help + help += "\n\nAvailable commands:\n" + for _, sc := range cmd.SubCommands { + help += fmt.Sprintf("- **%-12s**: %s\n", sc.Name, sc.Help) + } + + return help +} + func (cmd *Command) AddSubCommand(subCmd *Command) { if subCmd == nil { return @@ -260,3 +270,17 @@ func (cmd *Command) AddHelpSubCommand() { cmd.AddSubCommand(helpCmd) } + +func (cmd *Command) AddAboutSubCommand() { + aboutCmd := &Command{ + Name: "about", + Help: fmt.Sprintf("Information about Pagu"), + AppIDs: entity.AllAppIDs(), + TargetFlag: TargetMaskAll, + Handler: func(_ *entity.User, _ *Command, _ map[string]string) CommandResult { + return cmd.SuccessfulResult(cmd.AboutMessage()) + }, + } + + cmd.AddSubCommand(aboutCmd) +} diff --git a/internal/engine/engine.go b/internal/engine/engine.go index fa69c6fe..d2fc9f5f 100644 --- a/internal/engine/engine.go +++ b/internal/engine/engine.go @@ -149,6 +149,7 @@ func newBotEngine(ctx context.Context, rootCmd.AddSubCommand(phoenixCmd.GetCommand()) rootCmd.AddHelpSubCommand() + rootCmd.AddAboutSubCommand() return &BotEngine{ ctx: ctx, From 0ab9b421ae39a2c422f2612973f0b9bd7b864dfc Mon Sep 17 00:00:00 2001 From: Mohammad Hasan Saeedkia <170322053+MHSaeedkia@users.noreply.github.com> Date: Sat, 11 Jan 2025 20:49:30 +0330 Subject: [PATCH 2/6] CHANGE : move version.go to internal version pkg . --- cmd/cli/main.go | 2 +- version.go => internal/version/version.go | 0 2 files changed, 1 insertion(+), 1 deletion(-) rename version.go => internal/version/version.go (100%) diff --git a/cmd/cli/main.go b/cmd/cli/main.go index 9e74c5e5..46557845 100644 --- a/cmd/cli/main.go +++ b/cmd/cli/main.go @@ -5,11 +5,11 @@ import ( "os" "strings" - "github.com/pagu-project/pagu" pagucmd "github.com/pagu-project/pagu/cmd" "github.com/pagu-project/pagu/config" "github.com/pagu-project/pagu/internal/engine" "github.com/pagu-project/pagu/internal/entity" + pagu "github.com/pagu-project/pagu/internal/version" "github.com/pagu-project/pagu/pkg/log" "github.com/spf13/cobra" ) diff --git a/version.go b/internal/version/version.go similarity index 100% rename from version.go rename to internal/version/version.go From 009150eab8a0e3665311c86fda029e396b5bdb71 Mon Sep 17 00:00:00 2001 From: Mohammad Hasan Saeedkia <170322053+MHSaeedkia@users.noreply.github.com> Date: Sun, 12 Jan 2025 20:35:45 +0330 Subject: [PATCH 3/6] CHANGE : delete alias in importing version pkg --- cmd/cli/main.go | 4 ++-- cmd/discord/main.go | 4 ++-- cmd/grpc/main.go | 4 ++-- cmd/http/main.go | 4 ++-- cmd/telegram/main.go | 4 ++-- internal/engine/command/command.go | 2 +- internal/version/version.go | 2 +- 7 files changed, 12 insertions(+), 12 deletions(-) diff --git a/cmd/cli/main.go b/cmd/cli/main.go index 46557845..828a3d21 100644 --- a/cmd/cli/main.go +++ b/cmd/cli/main.go @@ -9,7 +9,7 @@ import ( "github.com/pagu-project/pagu/config" "github.com/pagu-project/pagu/internal/engine" "github.com/pagu-project/pagu/internal/entity" - pagu "github.com/pagu-project/pagu/internal/version" + "github.com/pagu-project/pagu/internal/version" "github.com/pagu-project/pagu/pkg/log" "github.com/spf13/cobra" ) @@ -52,7 +52,7 @@ func run(cmd *cobra.Command, _ []string) { func main() { rootCmd := &cobra.Command{ Use: "pagu-cli", - Version: pagu.StringVersion(), + Version: version.StringVersion(), Run: run, } diff --git a/cmd/discord/main.go b/cmd/discord/main.go index 0288df7c..5a81f276 100644 --- a/cmd/discord/main.go +++ b/cmd/discord/main.go @@ -2,7 +2,7 @@ package main import ( "github.com/pagu-project/pagu/cmd" - pagu "github.com/pagu-project/pagu/internal/version" + "github.com/pagu-project/pagu/internal/version" "github.com/spf13/cobra" ) @@ -11,7 +11,7 @@ var configPath string func main() { rootCmd := &cobra.Command{ Use: "pagu-discord", - Version: pagu.StringVersion(), + Version: version.StringVersion(), } rootCmd.PersistentFlags().StringVarP(&configPath, "config", "c", "./config.yml", "config path ./config.yml") diff --git a/cmd/grpc/main.go b/cmd/grpc/main.go index cf359636..4213dfd1 100644 --- a/cmd/grpc/main.go +++ b/cmd/grpc/main.go @@ -2,14 +2,14 @@ package main import ( "github.com/pagu-project/pagu/cmd" - pagu "github.com/pagu-project/pagu/internal/version" + "github.com/pagu-project/pagu/internal/version" "github.com/spf13/cobra" ) func main() { rootCmd := &cobra.Command{ Use: "pagu-grpc", - Version: pagu.StringVersion(), + Version: version.StringVersion(), } runCommand(rootCmd) diff --git a/cmd/http/main.go b/cmd/http/main.go index 3de359cb..4644812e 100644 --- a/cmd/http/main.go +++ b/cmd/http/main.go @@ -2,14 +2,14 @@ package main import ( "github.com/pagu-project/pagu/cmd" - pagu "github.com/pagu-project/pagu/internal/version" + "github.com/pagu-project/pagu/internal/version" "github.com/spf13/cobra" ) func main() { rootCmd := &cobra.Command{ Use: "pagu-http", - Version: pagu.StringVersion(), + Version: version.StringVersion(), } runCommand(rootCmd) diff --git a/cmd/telegram/main.go b/cmd/telegram/main.go index 8cece160..067d4738 100644 --- a/cmd/telegram/main.go +++ b/cmd/telegram/main.go @@ -2,7 +2,7 @@ package main import ( "github.com/pagu-project/pagu/cmd" - pagu "github.com/pagu-project/pagu/internal/version" + "github.com/pagu-project/pagu/internal/version" "github.com/spf13/cobra" ) @@ -11,7 +11,7 @@ var configPath string func main() { rootCmd := &cobra.Command{ Use: "pagu-telegram", - Version: pagu.StringVersion(), + Version: version.StringVersion(), } rootCmd.PersistentFlags().StringVarP(&configPath, "config", "c", "./config.yml", "config path ./config.yml") diff --git a/internal/engine/command/command.go b/internal/engine/command/command.go index 833186aa..d5c8aa00 100644 --- a/internal/engine/command/command.go +++ b/internal/engine/command/command.go @@ -278,7 +278,7 @@ func (cmd *Command) AddAboutSubCommand() { AppIDs: entity.AllAppIDs(), TargetFlag: TargetMaskAll, Handler: func(_ *entity.User, _ *Command, _ map[string]string) CommandResult { - return cmd.SuccessfulResult(cmd.AboutMessage()) + return cmd.RenderResultTemplate(cmd.AboutMessage()) }, } diff --git a/internal/version/version.go b/internal/version/version.go index 24b0e9d8..5afba8f9 100644 --- a/internal/version/version.go +++ b/internal/version/version.go @@ -1,4 +1,4 @@ -package pagu +package version import "fmt" From ed41c0818eb15e0c2fde1f2149f0207d64b9e4af Mon Sep 17 00:00:00 2001 From: Mohammad Hasan Saeedkia <170322053+MHSaeedkia@users.noreply.github.com> Date: Tue, 14 Jan 2025 22:35:06 +0330 Subject: [PATCH 4/6] ADD : add about command . --- internal/engine/command/command.go | 32 +++++++++++++++++++----------- internal/engine/engine.go | 2 +- 2 files changed, 21 insertions(+), 13 deletions(-) diff --git a/internal/engine/command/command.go b/internal/engine/command/command.go index d5c8aa00..97af0628 100644 --- a/internal/engine/command/command.go +++ b/internal/engine/command/command.go @@ -7,6 +7,7 @@ import ( "strings" "github.com/pagu-project/pagu/internal/entity" + "github.com/pagu-project/pagu/internal/version" "github.com/pagu-project/pagu/pkg/utils" ) @@ -20,6 +21,11 @@ const errorTemplate = ` {{.err}} ` +const aboutTemplate = ` +**About pagu** +version : {{.about}} +` + var ( TargetMaskMainnet = 1 TargetMaskTestnet = 2 @@ -235,16 +241,6 @@ func (cmd *Command) HelpMessage() string { return help } -func (cmd *Command) AboutMessage() string { - help := cmd.Help - help += "\n\nAvailable commands:\n" - for _, sc := range cmd.SubCommands { - help += fmt.Sprintf("- **%-12s**: %s\n", sc.Name, sc.Help) - } - - return help -} - func (cmd *Command) AddSubCommand(subCmd *Command) { if subCmd == nil { return @@ -272,13 +268,25 @@ func (cmd *Command) AddHelpSubCommand() { } func (cmd *Command) AddAboutSubCommand() { + msg, _ := cmd.executeTemplate(aboutTemplate, map[string]any{"about": version.StringVersion()}) + msg += "\n\nAvailable commands:\n" + for _, sc := range cmd.SubCommands { + msg += fmt.Sprintf("- **%-12s**: %s\n", sc.Name, sc.Help) + } + msg += fmt.Sprintf("- **%-12s**: %s\n", "about", "Information about Pagu") + msg += fmt.Sprintf("- **%-12s**: %s\n", "help", "Help for pagu command") + aboutCmd := &Command{ Name: "about", - Help: fmt.Sprintf("Information about Pagu"), + Help: "Information about Pagu", AppIDs: entity.AllAppIDs(), TargetFlag: TargetMaskAll, Handler: func(_ *entity.User, _ *Command, _ map[string]string) CommandResult { - return cmd.RenderResultTemplate(cmd.AboutMessage()) + return CommandResult{ + Title: fmt.Sprintf("%v %v", "Information about Pagu", "\n"), + Message: msg, + Successful: true, + } }, } diff --git a/internal/engine/engine.go b/internal/engine/engine.go index d2fc9f5f..de896754 100644 --- a/internal/engine/engine.go +++ b/internal/engine/engine.go @@ -148,8 +148,8 @@ func newBotEngine(ctx context.Context, rootCmd.AddSubCommand(marketCmd.GetCommand()) rootCmd.AddSubCommand(phoenixCmd.GetCommand()) - rootCmd.AddHelpSubCommand() rootCmd.AddAboutSubCommand() + rootCmd.AddHelpSubCommand() return &BotEngine{ ctx: ctx, From b51f77c88d46ac4cc690e84acec1e7fb0f7e4516 Mon Sep 17 00:00:00 2001 From: Mohammad Hasan Saeedkia <170322053+MHSaeedkia@users.noreply.github.com> Date: Tue, 14 Jan 2025 22:47:32 +0330 Subject: [PATCH 5/6] CHANGE : add example to README.md about command --- deployment/README.md | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/deployment/README.md b/deployment/README.md index 773dfcc7..60fc03c8 100644 --- a/deployment/README.md +++ b/deployment/README.md @@ -33,6 +33,12 @@ Use the following command to create the network: docker network create pagu_network ``` +Now, you can check the verson of Pagu: + +```bash +about +``` + ### Deployment Overview The deployment system operates as follows: From 3e55f247acc80c47e076c29c09a22af513b4e44f Mon Sep 17 00:00:00 2001 From: Mohammad Hasan Saeedkia <170322053+MHSaeedkia@users.noreply.github.com> Date: Wed, 15 Jan 2025 18:29:38 +0330 Subject: [PATCH 6/6] FIX : AddAboutSubCommand function . update install.md and add example about command . --- INSTALL.md | 6 ++++++ deployment/README.md | 5 ----- internal/engine/command/command.go | 26 ++++++++------------------ 3 files changed, 14 insertions(+), 23 deletions(-) diff --git a/INSTALL.md b/INSTALL.md index 4f6a3f7a..8486a1ee 100644 --- a/INSTALL.md +++ b/INSTALL.md @@ -68,6 +68,12 @@ Now, you can interact with Pagu: calculate reward --stake=1000 --days=1 ``` +Check the verson of Pagu: + +```bash +about +``` + ## Contributing We are excited to welcome contributions to Pagu! To get started, follow these steps: diff --git a/deployment/README.md b/deployment/README.md index 60fc03c8..059eb18e 100644 --- a/deployment/README.md +++ b/deployment/README.md @@ -33,11 +33,6 @@ Use the following command to create the network: docker network create pagu_network ``` -Now, you can check the verson of Pagu: - -```bash -about -``` ### Deployment Overview diff --git a/internal/engine/command/command.go b/internal/engine/command/command.go index 97af0628..0d4b3656 100644 --- a/internal/engine/command/command.go +++ b/internal/engine/command/command.go @@ -23,7 +23,7 @@ const errorTemplate = ` const aboutTemplate = ` **About pagu** -version : {{.about}} +version : {{.version}} ` var ( @@ -268,25 +268,15 @@ func (cmd *Command) AddHelpSubCommand() { } func (cmd *Command) AddAboutSubCommand() { - msg, _ := cmd.executeTemplate(aboutTemplate, map[string]any{"about": version.StringVersion()}) - msg += "\n\nAvailable commands:\n" - for _, sc := range cmd.SubCommands { - msg += fmt.Sprintf("- **%-12s**: %s\n", sc.Name, sc.Help) - } - msg += fmt.Sprintf("- **%-12s**: %s\n", "about", "Information about Pagu") - msg += fmt.Sprintf("- **%-12s**: %s\n", "help", "Help for pagu command") - + cmd.ResultTemplate = aboutTemplate aboutCmd := &Command{ - Name: "about", - Help: "Information about Pagu", - AppIDs: entity.AllAppIDs(), - TargetFlag: TargetMaskAll, + Name: "about", + Help: "About Pagu", + AppIDs: entity.AllAppIDs(), + TargetFlag: TargetMaskAll, + ResultTemplate: aboutTemplate, Handler: func(_ *entity.User, _ *Command, _ map[string]string) CommandResult { - return CommandResult{ - Title: fmt.Sprintf("%v %v", "Information about Pagu", "\n"), - Message: msg, - Successful: true, - } + return cmd.RenderResultTemplate("version", version.StringVersion()) }, }