From 8c3e155ca995ca4a8b277490a3004c6dfb05622f Mon Sep 17 00:00:00 2001 From: nazunalika Date: Sat, 1 Jan 2022 16:41:59 -0700 Subject: [PATCH] add dry run --- modules/paste/fpaste.go | 4 ++++ modules/paste/method.go | 15 ++++++++++----- modules/setting/setting.go | 2 ++ rpaste.go | 17 ++++++++++++++--- 4 files changed, 30 insertions(+), 8 deletions(-) diff --git a/modules/paste/fpaste.go b/modules/paste/fpaste.go index a475a92..63032fc 100644 --- a/modules/paste/fpaste.go +++ b/modules/paste/fpaste.go @@ -64,6 +64,10 @@ func Fpaste(life string, lexer string, fileContent string) error { fmt.Println("Uploading...") resp, err := http.PostForm(rurl.String(), form) + if err != nil { + fmt.Printf("Could not contact fpaste endpoint (%s)\n", fpasteURL) + os.Exit(1) + } // The response comes back as bytes, so we copy the response buffer into io // and string it out diff --git a/modules/paste/method.go b/modules/paste/method.go index d3f0832..92e4409 100644 --- a/modules/paste/method.go +++ b/modules/paste/method.go @@ -25,6 +25,7 @@ func runPaste(ctx *cli.Context) error { stdMethod := utility.StdInChecker() sysInfoMethod := ctx.Bool("sysinfo") pasteBinGoTo := ctx.String("pastebin") + dryMode := ctx.Bool("dry") // Check sysinfo is enabled and run through all the required stuff if sysInfoMethod { @@ -61,11 +62,15 @@ func runPaste(ctx *cli.Context) error { // Check that PasteData is text, and not binary // fmt.Println("You cannot upload binary data.") - switch pasteBinGoTo { - case "rpaste": - Rpaste(ctx.String("life"), ctx.String("type"), PasteData) - case "fpaste": - Fpaste(ctx.String("life"), ctx.String("type"), PasteData) + if dryMode { + fmt.Printf(PasteData) + } else { + switch pasteBinGoTo { + case "rpaste": + Rpaste(ctx.String("life"), ctx.String("type"), PasteData) + case "fpaste": + Fpaste(ctx.String("life"), ctx.String("type"), PasteData) + } } return nil diff --git a/modules/setting/setting.go b/modules/setting/setting.go index 85db044..a54df36 100644 --- a/modules/setting/setting.go +++ b/modules/setting/setting.go @@ -15,6 +15,8 @@ var ( AppBuiltWith string AppConf string AppVer string + BasicDmidecode bool + DryMode bool LexerType string LifeTime string PasteBinService string diff --git a/rpaste.go b/rpaste.go index be13891..4df8db3 100644 --- a/rpaste.go +++ b/rpaste.go @@ -22,9 +22,11 @@ var ( DefaultLexer = "text" DefaultLifeTime = "1hour" // This will end up being dynamic in the future - DefaultPasteBin = "rpaste" - DefaultSysInfo = false - ShortOption = true + DefaultPasteBin = "rpaste" + DefaultSysInfo = false + DefaultDryMode = false + DefaultBasicDmidecode = false + ShortOption = true ) // Initialize default settings @@ -32,10 +34,12 @@ func init() { setting.AppName = AppName setting.AppVer = Version setting.AppConf = DefaultConf + setting.DryMode = DefaultDryMode setting.LexerType = DefaultLexer setting.LifeTime = DefaultLifeTime setting.PasteBinService = DefaultPasteBin setting.SysInfo = DefaultSysInfo + setting.BasicDmidecode = DefaultBasicDmidecode // read config? } @@ -96,6 +100,13 @@ See rpaste(1)`, Usage: "Collects general system information (disables stdin and file input)", Required: false, }, + &cli.BoolFlag{ + Name: "dry", + Aliases: []string{"d"}, + Value: setting.DryMode, + Usage: "Turns on dry mode, which doesn't paste the output, but shows the data to stdin", + Required: false, + }, &cli.StringFlag{ Name: "pastebin", Aliases: []string{"p"},