Commit 57139bbe authored by Heiko Reese's avatar Heiko Reese
Browse files

Unknown changes from the past…

parent dcd4c8d0
Pipeline #108600 passed with stage
in 30 seconds
......@@ -16,8 +16,10 @@ package cmd
import (
"bytes"
"errors"
"io/ioutil"
"log"
"path/filepath"
"strings"
"text/template"
......@@ -33,6 +35,18 @@ var (
}
)
func ReadFirstChunkFromFile(filename string) (string, error) {
content, err := ioutil.ReadFile(filename)
if err != nil {
return "", err
}
tokens := strings.Fields(string(content))
if len(tokens) < 1 {
return "", errors.New("Unable to find useful data in" + filename)
}
return strings.TrimSpace(tokens[0]), nil
}
// getpdfCmd represents the getpdf command
var getpdfCmd = &cobra.Command{
Use: "getpdf",
......@@ -40,29 +54,36 @@ var getpdfCmd = &cobra.Command{
// Long: ``,
Run: func(cmd *cobra.Command, args []string) {
var (
RequestID string = "NONE"
filename string
filename string
)
viper.BindPFlags(cmd.PersistentFlags())
viper.Unmarshal(&getPdfData)
REQID:
switch {
// handle --requestid
if viper.IsSet("requestid") {
RequestID = viper.GetString("requestid")
}
case viper.IsSet("requestid"):
getPdfData.RequestID = viper.GetString("requestid")
// handle --requestidfile
if viper.IsSet("requestidfile") {
content, err := ioutil.ReadFile(viper.GetString("requestidfile"))
case viper.IsSet("requestidfile"):
chunk, err := ReadFirstChunkFromFile(viper.GetString("requestidfile"))
if err != nil {
log.Fatal(err)
log.Fatalf("Unable to read request if from %s", viper.GetString("requestidfile"))
}
tokens := strings.Fields(string(content))
if len(tokens) < 1 {
log.Fatalf("No request id found in %s", viper.GetString("requestidfile"))
getPdfData.RequestID = chunk
// try to find a request id file
default:
matches, err := filepath.Glob(`*.request-id.txt`)
if err != nil || len(matches) == 0 {
log.Fatal("Please specify a request id")
}
for _, file := range matches {
chunk, err := ReadFirstChunkFromFile(file)
if err == nil {
getPdfData.RequestID = chunk
break REQID
}
}
RequestID = strings.TrimSpace(tokens[0])
}
if RequestID == "NONE" {
log.Fatal("Please specify a request id")
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment