// method runner for pasting package paste import ( "fmt" "io/ioutil" "os" "github.com/rocky-linux/rpaste/modules/utility" "github.com/urfave/cli/v2" ) var ( PasteMethod = &cli.Command{ Name: "Paste", Usage: "Pastes content to pastebin", Description: `This is the default action for the rpaste utility.`, Action: runPaste, } PasteData string ) func runPaste(ctx *cli.Context) error { // check stdMethod := utility.StdInChecker() sysInfoMethod := ctx.Bool("sysinfo") // Check sysinfo is enabled and run through all the required stuff if sysInfoMethod { PasteData = SysInfoGather() } if stdMethod && PasteData == "" { fio, err := os.Stdin.Stat() if (fio.Mode() & os.ModeCharDevice) == 0 { bytes, _ := ioutil.ReadAll(os.Stdin) PasteData = string(bytes) } else if err != nil { fmt.Printf("Could not read from stdin: (%s)\n", err) os.Exit(1) } } else if !stdMethod && PasteData == "" { argList := os.Args lastArg := argList[len(argList)-1] fileBytes, err := ioutil.ReadFile(lastArg) if err != nil { panic(err) } PasteData = string(fileBytes) } // Check that PasteData is text, and not binary fmt.Println(PasteData) return nil }