From c0640ac89fc449a1913ad8427b53332cb07addf3 Mon Sep 17 00:00:00 2001 From: Mohammad Hasan Saeedkia <170322053+MHSaeedkia@users.noreply.github.com> Date: Wed, 15 Jan 2025 20:27:44 +0330 Subject: [PATCH] feat: add about command (#270) --- INSTALL.md | 6 ++++++ 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 ++-- deployment/README.md | 1 + internal/engine/command/command.go | 22 ++++++++++++++++++++++ internal/engine/engine.go | 1 + version.go => internal/version/version.go | 2 +- 10 files changed, 41 insertions(+), 11 deletions(-) rename version.go => internal/version/version.go (94%) 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/cmd/cli/main.go b/cmd/cli/main.go index 9e74c5e5..828a3d21 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" + "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 165316ae..5a81f276 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" + "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 e41167e1..4213dfd1 100644 --- a/cmd/grpc/main.go +++ b/cmd/grpc/main.go @@ -1,15 +1,15 @@ package main import ( - "github.com/pagu-project/pagu" "github.com/pagu-project/pagu/cmd" + "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 a999fa49..4644812e 100644 --- a/cmd/http/main.go +++ b/cmd/http/main.go @@ -1,15 +1,15 @@ package main import ( - "github.com/pagu-project/pagu" "github.com/pagu-project/pagu/cmd" + "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 1f8d539f..067d4738 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" + "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/deployment/README.md b/deployment/README.md index 773dfcc7..059eb18e 100644 --- a/deployment/README.md +++ b/deployment/README.md @@ -33,6 +33,7 @@ Use the following command to create the network: docker network create pagu_network ``` + ### Deployment Overview The deployment system operates as follows: diff --git a/internal/engine/command/command.go b/internal/engine/command/command.go index b4b716a0..0d4b3656 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 : {{.version}} +` + var ( TargetMaskMainnet = 1 TargetMaskTestnet = 2 @@ -260,3 +266,19 @@ func (cmd *Command) AddHelpSubCommand() { cmd.AddSubCommand(helpCmd) } + +func (cmd *Command) AddAboutSubCommand() { + cmd.ResultTemplate = aboutTemplate + aboutCmd := &Command{ + Name: "about", + Help: "About Pagu", + AppIDs: entity.AllAppIDs(), + TargetFlag: TargetMaskAll, + ResultTemplate: aboutTemplate, + Handler: func(_ *entity.User, _ *Command, _ map[string]string) CommandResult { + return cmd.RenderResultTemplate("version", version.StringVersion()) + }, + } + + cmd.AddSubCommand(aboutCmd) +} diff --git a/internal/engine/engine.go b/internal/engine/engine.go index fa69c6fe..de896754 100644 --- a/internal/engine/engine.go +++ b/internal/engine/engine.go @@ -148,6 +148,7 @@ func newBotEngine(ctx context.Context, rootCmd.AddSubCommand(marketCmd.GetCommand()) rootCmd.AddSubCommand(phoenixCmd.GetCommand()) + rootCmd.AddAboutSubCommand() rootCmd.AddHelpSubCommand() return &BotEngine{ diff --git a/version.go b/internal/version/version.go similarity index 94% rename from version.go rename to internal/version/version.go index cc4552d8..06a1af24 100644 --- a/version.go +++ b/internal/version/version.go @@ -1,4 +1,4 @@ -package pagu +package version import "fmt"