mirror of
https://github.com/byReqz/go-etcher.git
synced 2024-12-25 12:41:49 +00:00
add input flags
This commit is contained in:
parent
bdff18e421
commit
a7378b14e0
1
go.mod
1
go.mod
@ -14,6 +14,7 @@ require (
|
||||
github.com/mattn/go-runewidth v0.0.13 // indirect
|
||||
github.com/mitchellh/colorstring v0.0.0-20190213212951-d06e56a500db // indirect
|
||||
github.com/rivo/uniseg v0.2.0 // indirect
|
||||
github.com/spf13/pflag v1.0.5 // indirect
|
||||
golang.org/x/crypto v0.0.0-20211215153901-e495a2d5b3d3 // indirect
|
||||
golang.org/x/sys v0.0.0-20211216021012-1d35b9e2eb4e // indirect
|
||||
golang.org/x/term v0.0.0-20210927222741-03fcf44c2211 // indirect
|
||||
|
2
go.sum
2
go.sum
@ -24,6 +24,8 @@ github.com/rivo/uniseg v0.2.0 h1:S1pD9weZBuJdFmowNwbpi7BJ8TNftyUImj/0WQi72jY=
|
||||
github.com/rivo/uniseg v0.2.0/go.mod h1:J6wj4VEh+S6ZtnVlnTBMWIodfgj8LQOQFoIToxlJtxc=
|
||||
github.com/schollz/progressbar/v3 v3.8.5 h1:VcmmNRO+eFN3B0m5dta6FXYXY+MEJmXdWoIS+jjssQM=
|
||||
github.com/schollz/progressbar/v3 v3.8.5/go.mod h1:ewO25kD7ZlaJFTvMeOItkOZa8kXu1UvFs379htE8HMQ=
|
||||
github.com/spf13/pflag v1.0.5 h1:iy+VFUOCP1a+8yFto/drg2CJ5u0yRoB7fZw3DKv/JXA=
|
||||
github.com/spf13/pflag v1.0.5/go.mod h1:McXfInJRrz4CZXVZOBLb0bTZqETkiAhM9Iw0y3An2Bg=
|
||||
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
|
||||
github.com/stretchr/testify v1.3.0 h1:TivCn/peBQ7UY8ooIcPgZFpTNSz0Q2U6UrFlUfqbe0Q=
|
||||
github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI=
|
||||
|
33
main.go
33
main.go
@ -9,10 +9,22 @@ import (
|
||||
"github.com/schollz/progressbar/v3"
|
||||
"github.com/fatih/color"
|
||||
"github.com/briandowns/spinner"
|
||||
flag "github.com/spf13/pflag"
|
||||
)
|
||||
|
||||
var device string
|
||||
var input string
|
||||
var force bool
|
||||
|
||||
func init() {
|
||||
flag.StringVarP(&device, "device", "d", "", "target device")
|
||||
flag.StringVarP(&input, "input", "i", "", "input file")
|
||||
flag.BoolVarP(&force, "force", "f", false, "override safety features")
|
||||
flag.Parse()
|
||||
}
|
||||
|
||||
func GetPath() string {
|
||||
fmt.Print("Path to image: ")
|
||||
fmt.Print("[ ", color.YellowString("i"), " ] Please input your image file: ")
|
||||
var path string
|
||||
_, err := fmt.Scanln(&path)
|
||||
if err != nil {
|
||||
@ -30,7 +42,7 @@ func GetPath() string {
|
||||
}
|
||||
|
||||
func GetDest() string {
|
||||
fmt.Print("Path to Destination: ")
|
||||
fmt.Print("[ ", color.YellowString("i"), " ] Please input destination: ")
|
||||
var dest string
|
||||
_, err := fmt.Scanln(&dest)
|
||||
if err != nil {
|
||||
@ -83,15 +95,18 @@ func Sync(image *os.File, target *os.File) error {
|
||||
func main() {
|
||||
s := spinner.New(spinner.CharSets[14], 100*time.Millisecond)
|
||||
|
||||
// if not given via arg
|
||||
path := GetPath()
|
||||
// if not given via arg
|
||||
dest := GetDest()
|
||||
if input == "" {
|
||||
input = GetPath()
|
||||
}
|
||||
|
||||
if device == "" {
|
||||
device = GetDest()
|
||||
}
|
||||
|
||||
s.Prefix = "[ "
|
||||
s.Suffix = " ] Getting file details"
|
||||
s.Start()
|
||||
stat, err := os.Stat(path)
|
||||
stat, err := os.Stat(input)
|
||||
if err != nil {
|
||||
s.Stop()
|
||||
fmt.Println("\r[", color.RedString("✘"), "] Getting file details ")
|
||||
@ -104,13 +119,13 @@ func main() {
|
||||
s.Prefix = "[ "
|
||||
s.Suffix = " ] Opening files"
|
||||
s.Start()
|
||||
image, err := os.Open(path)
|
||||
image, err := os.Open(input)
|
||||
if err != nil {
|
||||
s.Stop()
|
||||
fmt.Println("\r[", color.RedString("✘"), "] Opening files ")
|
||||
log.Fatal(err)
|
||||
}
|
||||
target, err := os.OpenFile(dest, os.O_RDWR, 0660)
|
||||
target, err := os.OpenFile(device, os.O_RDWR, 0660)
|
||||
if err != nil {
|
||||
s.Stop()
|
||||
fmt.Println("\r[", color.RedString("✘"), "] Opening files ")
|
||||
|
Loading…
Reference in New Issue
Block a user