From d661b29efedcd94c2007bdf919608a675c996574 Mon Sep 17 00:00:00 2001 From: appleboy Date: Sat, 8 Mar 2025 22:37:30 +0800 Subject: [PATCH] feat: add debug mode for plugin configuration dumping - Add a new dependency for godump in go.mod - Import godump in main.go - Introduce a debug flag in the CLI options - Update the run function to include the debug flag - Add logic to dump the plugin configuration if debug mode is enabled - Extend the plugin struct to include a debug field Signed-off-by: appleboy --- go.mod | 1 + go.sum | 2 ++ main.go | 11 +++++++++++ plugin.go | 1 + 4 files changed, 15 insertions(+) diff --git a/go.mod b/go.mod index fb2efb3..a976f57 100644 --- a/go.mod +++ b/go.mod @@ -7,6 +7,7 @@ require ( github.com/joho/godotenv v1.5.1 github.com/stretchr/testify v1.10.0 github.com/urfave/cli/v2 v2.27.6 + github.com/yassinebenaid/godump v0.11.1 ) require ( diff --git a/go.sum b/go.sum index 0c28df8..e3df2cc 100644 --- a/go.sum +++ b/go.sum @@ -64,6 +64,8 @@ github.com/urfave/cli/v2 v2.27.6 h1:VdRdS98FNhKZ8/Az8B7MTyGQmpIr36O1EHybx/LaZ4g= github.com/urfave/cli/v2 v2.27.6/go.mod h1:3Sevf16NykTbInEnD0yKkjDAeZDS0A6bzhBH5hrMvTQ= github.com/xrash/smetrics v0.0.0-20240521201337-686a1a2994c1 h1:gEOO8jv9F4OT7lGCjxCBTO/36wtF6j2nSip77qHd4x4= github.com/xrash/smetrics v0.0.0-20240521201337-686a1a2994c1/go.mod h1:Ohn+xnUBiLI6FVj/9LpzZWtj1/D6lUovWYBkxHVV3aM= +github.com/yassinebenaid/godump v0.11.1 h1:SPujx/XaYqGDfmNh7JI3dOyCUVrG0bG2duhO3Eh2EhI= +github.com/yassinebenaid/godump v0.11.1/go.mod h1:dc/0w8wmg6kVIvNGAzbKH1Oa54dXQx8SNKh4dPRyW44= github.com/yuin/goldmark v1.4.13/go.mod h1:6yULJ656Px+3vBD8DxQVa3kxgyrAnzto9xy5taEt/CY= golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w= golang.org/x/crypto v0.0.0-20210921155107-089bfa567519/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc= diff --git a/main.go b/main.go index c9360b4..945eddc 100644 --- a/main.go +++ b/main.go @@ -8,6 +8,7 @@ import ( "github.com/joho/godotenv" "github.com/urfave/cli/v2" + "github.com/yassinebenaid/godump" ) // Version set at compile-time @@ -235,6 +236,11 @@ func main() { Usage: "The target deployment environment for the running build. This value is only available to promotion and rollback pipelines.", EnvVars: []string{"DRONE_DEPLOY_TO", "CI_PIPELINE_DEPLOY_TARGET"}, }, + &cli.BoolFlag{ + Name: "debug", + Usage: "Enable debug mode.", + EnvVars: []string{"PLUGIN_DEBUG", "INPUT_DEBUG", "DEBUG"}, + }, } if err := app.Run(os.Args); err != nil { @@ -289,6 +295,7 @@ func run(c *cli.Context) error { Color: c.String("color"), Drone: c.Bool("drone") || c.String("ci.environment") == "woodpecker", GitHub: c.Bool("github"), + Debug: c.Bool("debug"), }, Payload: Payload{ Wait: c.Bool("wait"), @@ -298,5 +305,9 @@ func run(c *cli.Context) error { }, } + if plugin.Config.Debug { + _ = godump.Dump(plugin) + } + return plugin.Exec(c.Context) } diff --git a/plugin.go b/plugin.go index fd47a49..4b66b8e 100644 --- a/plugin.go +++ b/plugin.go @@ -81,6 +81,7 @@ type ( File []string Drone bool GitHub bool + Debug bool } // EmbedFooterObject for Embed Footer Structure.