Browse Source

Fix bug & simplify

pull/793/head
xpetit 3 years ago
parent
commit
e9d4837d42
No known key found for this signature in database
GPG Key ID: 97C60669182C17A5
  1. 16
      sh/debian/ubuntu/system/usr/local/src/format/main.go

16
sh/debian/ubuntu/system/usr/local/src/format/main.go diff.vendored

@ -159,27 +159,21 @@ func main() {
renderTable(table) renderTable(table)
// Select the USB flash drive to format // Select the USB flash drive to format
if len(devices) == 1 { fmt.Println(`Enter the number of the disk you want to format (or "exit"):`)
fmt.Println(`Press ENTER to format the disk (or "exit")`)
} else {
fmt.Println(`Enter the number of the disk you want to format (or "exit"):`)
}
var choice string var choice string
fmt.Scanln(&choice) fmt.Scanln(&choice)
if strings.ToLower(choice) == "exit" { if strings.ToLower(choice) == "exit" {
return return
} }
var nb int var nb int
if choice != "" { nb, err := strconv.Atoi(choice)
nb, err := strconv.Atoi(choice) if err != nil || nb < 0 || nb >= len(devices) {
if err != nil || nb < 0 || nb >= len(devices) { fatalln("Wrong disk number:", choice)
fatalln("Wrong disk number:", choice)
}
} }
device := devices[nb] device := devices[nb]
// Get a list of the USB flash drive mount points // Get a list of the USB flash drive mount points
b, err := os.ReadFile("/proc/mounts") b, err = os.ReadFile("/proc/mounts")
expect(nil, err, "list the mount points") expect(nil, err, "list the mount points")
lines := strings.Split(string(b), "\n") lines := strings.Split(string(b), "\n")
var mountPoints []string var mountPoints []string

Loading…
Cancel
Save