68 lines
1.5 KiB
Go
68 lines
1.5 KiB
Go
// method runner for pasting
|
|
package paste
|
|
|
|
import (
|
|
"fmt"
|
|
"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
|
|
stdResults := utility.StdInChecker()
|
|
|
|
// If there's no more than 1 argument (the executable itself is arg 0), we
|
|
// will check for stdin, and if not, print out the usage information.
|
|
//if stdResults {
|
|
// 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 {
|
|
// cli.ShowAppHelp(ctx)
|
|
// os.Exit(0)
|
|
//}
|
|
|
|
// Check args for a file or sysinfo
|
|
//if len(PasteData) == 0 {
|
|
// if ctx.Bool("sysinfo") {
|
|
// //PasteData = GatherSysInfo()
|
|
// PasteData = "Sys Info"
|
|
// } else {
|
|
// // Path is expected at the end of the command (matches current rpaste)
|
|
// 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(len(PasteData))
|
|
for i, arg := range os.Args {
|
|
fmt.Println("item", i, "is", arg)
|
|
}
|
|
|
|
return nil
|
|
}
|