fixes
This commit is contained in:
parent
0cdad2344e
commit
6ede82b418
@ -26,12 +26,20 @@ func runPaste(ctx *cli.Context) error {
|
|||||||
sysInfoMethod := ctx.Bool("sysinfo")
|
sysInfoMethod := ctx.Bool("sysinfo")
|
||||||
pasteBinGoTo := ctx.String("pastebin")
|
pasteBinGoTo := ctx.String("pastebin")
|
||||||
dryMode := ctx.Bool("dry")
|
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
|
// Check sysinfo is enabled and run through all the required stuff
|
||||||
if sysInfoMethod {
|
if sysInfoMethod {
|
||||||
PasteData = SysInfoGather()
|
PasteData = SysInfoGather()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Paste Data is empty, checking if input is from stdin
|
||||||
if stdMethod && PasteData == "" {
|
if stdMethod && PasteData == "" {
|
||||||
fio, err := os.Stdin.Stat()
|
fio, err := os.Stdin.Stat()
|
||||||
if (fio.Mode() & os.ModeCharDevice) == 0 {
|
if (fio.Mode() & os.ModeCharDevice) == 0 {
|
||||||
@ -42,14 +50,42 @@ func runPaste(ctx *cli.Context) error {
|
|||||||
os.Exit(1)
|
os.Exit(1)
|
||||||
}
|
}
|
||||||
} else if !stdMethod && PasteData == "" {
|
} 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
|
argList := os.Args
|
||||||
lastArg := argList[len(argList)-1]
|
lastArg := argList[len(argList)-1]
|
||||||
if lastArg != os.Args[0] {
|
if lastArg != os.Args[0] {
|
||||||
fileBytes, err := ioutil.ReadFile(lastArg)
|
// Check if input exists
|
||||||
if err != nil {
|
checkarg, _ := utility.IsExist(lastArg)
|
||||||
panic(err)
|
// 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)
|
Rpaste(ctx.String("life"), ctx.String("type"), PasteData)
|
||||||
case "fpaste":
|
case "fpaste":
|
||||||
Fpaste(ctx.String("life"), ctx.String("type"), PasteData)
|
Fpaste(ctx.String("life"), ctx.String("type"), PasteData)
|
||||||
|
default:
|
||||||
|
fmt.Printf("You have provided an unknown paste bin.\n\n")
|
||||||
|
cli.ShowAppHelp(ctx)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -18,3 +18,12 @@ func StdInChecker() bool {
|
|||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func stringInSlice(s string, list []string) bool {
|
||||||
|
for _, b := range list {
|
||||||
|
if b == s {
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user