2020-01-02 07:14:51 +01:00
package main
import (
"log"
"os"
2020-06-07 03:23:46 +02:00
2020-01-03 14:28:31 +01:00
"github.com/jesseduffield/horcrux/pkg/commands"
2020-01-03 06:27:36 +01:00
)
2020-01-03 02:56:56 +01:00
2020-01-02 07:14:51 +01:00
func main ( ) {
2020-01-03 14:16:45 +01:00
// I'd use `flaggy` but I like the idea of this repo having no dependencies
// Unfortunately that means I'm awkwardly making use of the standard flag package
2020-01-02 07:14:51 +01:00
if len ( os . Args ) < 2 {
usage ( )
}
2020-01-03 06:42:11 +01:00
2020-01-03 14:23:39 +01:00
if os . Args [ 1 ] == "bind" {
2020-01-02 07:14:51 +01:00
var dir string
if len ( os . Args ) == 2 {
dir = "."
} else {
dir = os . Args [ 2 ]
}
2020-06-14 05:44:11 +02:00
paths , err := commands . GetHorcruxPathsInDir ( dir )
if err != nil {
2020-01-02 07:14:51 +01:00
log . Fatal ( err )
}
2020-06-14 05:44:11 +02:00
overwrite := false
for {
if err := commands . Bind ( paths , "" , overwrite ) ; err != nil {
if err != os . ErrExist {
log . Fatal ( err )
}
overwriteResponse := commands . Prompt ( "A file already exists at destination. Overwrite? (Y/N):" )
if overwriteResponse == "Y" || overwriteResponse == "y" || overwriteResponse == "yes" {
overwrite = true
} else {
log . Fatal ( "You have chosen not to overwrite the file. Cancelling." )
}
} else {
break
}
}
2020-01-03 14:23:39 +01:00
return
}
if os . Args [ len ( os . Args ) - 2 ] == "split" {
2020-01-02 07:14:51 +01:00
if len ( os . Args ) == 2 {
usage ( )
}
2020-01-03 06:42:11 +01:00
path := os . Args [ len ( os . Args ) - 1 ]
2020-06-07 03:23:46 +02:00
if err := commands . SplitWithPrompt ( path ) ; err != nil {
2020-01-02 07:14:51 +01:00
log . Fatal ( err )
}
2020-01-03 14:23:39 +01:00
return
2020-01-02 07:14:51 +01:00
}
2020-01-03 14:23:39 +01:00
usage ( )
2020-01-02 07:14:51 +01:00
}
func usage ( ) {
2020-01-03 06:46:03 +01:00
log . Fatal ( "usage: `horcrux bind [<directory>]` | `horcrux [-t] [-n] split <filename>`\n-n: number of horcruxes to make\n-t: number of horcruxes required to resurrect the original file\nexample: horcrux -t 3 -n 5 split diary.txt" )
2020-01-02 07:14:51 +01:00
}