From 6ede82b418d49b697177abbcb17ab2c23aaac9c3 Mon Sep 17 00:00:00 2001 From: nazunalika Date: Sun, 2 Jan 2022 10:03:04 -0700 Subject: [PATCH] fixes --- modules/paste/method.go | 47 ++++++++++++++++++++++++++++++++++---- modules/utility/parsers.go | 9 ++++++++ 2 files changed, 52 insertions(+), 4 deletions(-) diff --git a/modules/paste/method.go b/modules/paste/method.go index 92e4409..ac03dfd 100644 --- a/modules/paste/method.go +++ b/modules/paste/method.go @@ -26,12 +26,20 @@ func runPaste(ctx *cli.Context) error { sysInfoMethod := ctx.Bool("sysinfo") pasteBinGoTo := ctx.String("pastebin") dryMode := ctx.Bool("dry") + //timeInput := ctx.String("life") + //lexerInput := ctx.String("type") + + //verifyValues, err := utility.VerifyInputs(timeInput, lexerInput) + //if err != nil { + // fmt.Printf("%s", err) + //} // Check sysinfo is enabled and run through all the required stuff if sysInfoMethod { PasteData = SysInfoGather() } + // Paste Data is empty, checking if input is from stdin if stdMethod && PasteData == "" { fio, err := os.Stdin.Stat() if (fio.Mode() & os.ModeCharDevice) == 0 { @@ -42,14 +50,42 @@ func runPaste(ctx *cli.Context) error { os.Exit(1) } } else if !stdMethod && PasteData == "" { + // In the event that input is not from stdin, let's check if a file name + // was given to us. golang doesn't let us do the same thing that python, + // bash, perl, and others do, which is call the last index item with -1. + // Below is basically a hack where we get the length of the arguments, + // subtract by 1, and use that to get the last argument index number. argList := os.Args lastArg := argList[len(argList)-1] if lastArg != os.Args[0] { - fileBytes, err := ioutil.ReadFile(lastArg) - if err != nil { - panic(err) + // Check if input exists + checkarg, _ := utility.IsExist(lastArg) + // if it's true, check if it's a file + if checkarg { + checkfile, _ := utility.IsFile(lastArg) + // if it's a file, send it to the PasteData var + if checkfile { + fileBytes, err := ioutil.ReadFile(lastArg) + if err != nil { + panic(err) + } + PasteData = string(fileBytes) + } else { + fmt.Printf("%s is not a file\n", lastArg) + os.Exit(1) + } + } else { + // It doesn't exist, so we need to report if the reported location + // does not exist. Else, if it starts with a "-", just skip everything + // entirely. + if len(lastArg) > 1 && lastArg[:1] == "-" { + PasteData = "" + // This section is a bug for now - If a value to an arg is provided + // and it's not supposed to be a file, we still checked it above. + } else if !(len(lastArg) > 1 && lastArg[:1] == "-") { + fmt.Printf("File not found or is an argument value: %s\n", lastArg) + } } - PasteData = string(fileBytes) } } @@ -70,6 +106,9 @@ func runPaste(ctx *cli.Context) error { Rpaste(ctx.String("life"), ctx.String("type"), PasteData) case "fpaste": Fpaste(ctx.String("life"), ctx.String("type"), PasteData) + default: + fmt.Printf("You have provided an unknown paste bin.\n\n") + cli.ShowAppHelp(ctx) } } diff --git a/modules/utility/parsers.go b/modules/utility/parsers.go index 1d40a08..d1460b3 100644 --- a/modules/utility/parsers.go +++ b/modules/utility/parsers.go @@ -18,3 +18,12 @@ func StdInChecker() bool { return false } } + +func stringInSlice(s string, list []string) bool { + for _, b := range list { + if b == s { + return true + } + } + return false +}