feat: improve output
This commit is contained in:
parent
cfa8c7e9f9
commit
051e257fba
30
main.go
30
main.go
@ -101,10 +101,10 @@ func main() {
|
|||||||
fmt.Println()
|
fmt.Println()
|
||||||
fmt.Println("Press 'ctrl+c' to cancel")
|
fmt.Println("Press 'ctrl+c' to cancel")
|
||||||
time.Sleep(time.Second)
|
time.Sleep(time.Second)
|
||||||
fmt.Println()
|
|
||||||
fmt.Println()
|
|
||||||
|
|
||||||
for _, dsConsumedir := range cfg.ImportDirectories {
|
for _, dsConsumedir := range cfg.ImportDirectories {
|
||||||
|
fmt.Println()
|
||||||
|
fmt.Println()
|
||||||
fmt.Printf("Scanning folder '%s'\n", dsConsumedir)
|
fmt.Printf("Scanning folder '%s'\n", dsConsumedir)
|
||||||
fmt.Println()
|
fmt.Println()
|
||||||
fmt.Println()
|
fmt.Println()
|
||||||
@ -123,42 +123,42 @@ func main() {
|
|||||||
cmd := exec.Command("dsc", "-f", "json", "file-exists", path)
|
cmd := exec.Command("dsc", "-f", "json", "file-exists", path)
|
||||||
output, err := cmd.Output()
|
output, err := cmd.Output()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Printf("ERROR %v\n", err)
|
fmt.Printf(" ERROR %v\n", err)
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
var fileExistsResponse []FileExistsResult
|
var fileExistsResponse []FileExistsResult
|
||||||
if err := json.Unmarshal(output, &fileExistsResponse); err != nil {
|
if err := json.Unmarshal(output, &fileExistsResponse); err != nil {
|
||||||
fmt.Printf("ERROR parsing response: %v\n", err)
|
fmt.Printf(" ERROR parsing response: %v\n", err)
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
if fileExistsResponse[0].Exists {
|
if fileExistsResponse[0].Exists {
|
||||||
err := handleExistingFile(cfg, fileExistsResponse[0])
|
err := handleExistingFile(cfg, fileExistsResponse[0])
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Println("ERROR", err)
|
fmt.Println(" ERROR", err)
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
fmt.Println("Files does not exist, yet")
|
fmt.Println(" Files does not exist, yet")
|
||||||
if *uploadMissing {
|
if *uploadMissing {
|
||||||
fmt.Print("...uploading file..")
|
fmt.Print(" ...uploading file..")
|
||||||
cmd = exec.Command("dsc", "-f", "json", "upload", path)
|
cmd = exec.Command("dsc", "-f", "json", "upload", path)
|
||||||
output, err := cmd.Output()
|
output, err := cmd.Output()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Printf("\nERROR uploading: %v\n", err)
|
fmt.Printf("\n ERROR uploading: %v\n", err)
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
var uploadResult map[string]interface{}
|
var uploadResult map[string]interface{}
|
||||||
if err := json.Unmarshal(output, &uploadResult); err != nil {
|
if err := json.Unmarshal(output, &uploadResult); err != nil {
|
||||||
fmt.Printf("\nERROR parsing upload result: %v\n", err)
|
fmt.Printf("\n ERROR parsing upload result: %v\n", err)
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
if uploadResult["success"].(bool) {
|
if uploadResult["success"].(bool) {
|
||||||
fmt.Println(". done")
|
fmt.Println(". done")
|
||||||
} else {
|
} else {
|
||||||
fmt.Printf("\nERROR %v\n", uploadResult)
|
fmt.Printf("\n ERROR %v\n", uploadResult)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -192,7 +192,7 @@ func handleExistingFile(cfg config, fileExistsResponse FileExistsResult) error {
|
|||||||
|
|
||||||
var itemDetails DocspellItemDetails
|
var itemDetails DocspellItemDetails
|
||||||
if err := json.Unmarshal(output, &itemDetails); err != nil {
|
if err := json.Unmarshal(output, &itemDetails); err != nil {
|
||||||
return fmt.Errorf("pars item details: %w", err)
|
return fmt.Errorf("parse item details: %w", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
folder := "null"
|
folder := "null"
|
||||||
@ -207,17 +207,17 @@ func handleExistingFile(cfg config, fileExistsResponse FileExistsResult) error {
|
|||||||
} else if itemDetails.CorrespondingPerson != nil && itemDetails.CorrespondingPerson.Name != "" {
|
} else if itemDetails.CorrespondingPerson != nil && itemDetails.CorrespondingPerson.Name != "" {
|
||||||
corr = itemDetails.CorrespondingPerson.Name
|
corr = itemDetails.CorrespondingPerson.Name
|
||||||
}
|
}
|
||||||
fmt.Printf("File already exists: '%s @ %s/app/item/%s'\n", itemName, cfg.DocspellURL, itemID)
|
fmt.Printf(" File already exists: '%s @ %s/app/item/%s'\n", itemName, cfg.DocspellURL, itemID)
|
||||||
|
|
||||||
state := item.State
|
state := item.State
|
||||||
if state != "confirmed" {
|
if state != "confirmed" {
|
||||||
fmt.Println("... but is not confirmed yet - not doing anything.")
|
fmt.Println(" ... but is not confirmed yet - not doing anything.")
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
itemDate := item.ItemDate
|
itemDate := item.ItemDate
|
||||||
if itemDate == 0 {
|
if itemDate == 0 {
|
||||||
fmt.Println("... but has no date - not doing anything.")
|
fmt.Println(" ... but has no date - not doing anything.")
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
date := time.Unix(itemDate/1000, 0)
|
date := time.Unix(itemDate/1000, 0)
|
||||||
@ -234,7 +234,7 @@ func handleExistingFile(cfg config, fileExistsResponse FileExistsResult) error {
|
|||||||
return fmt.Errorf("move file: %w", err)
|
return fmt.Errorf("move file: %w", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
fmt.Printf("... moving to archive by date ('%s')\n", curDir)
|
fmt.Printf(" ... moving to archive by date ('%s')\n", curDir)
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user