summaryrefslogtreecommitdiff
path: root/main.go
blob: 676ae29ae6a679ce0bb99f3b526c72f9507eebc2 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
// SPDX-FileCopyrightText: 2026 Terin Stock <terinjokes@gmail.com>
// SPDX-License-Identifier: EUPL-1.2

package main

import (
	"flag"
	"fmt"
	"os"

	humanize "github.com/dustin/go-humanize"
	"go.terinstock.com/odescsitoolbox/toolbox"
)

func listCDs(d *toolbox.Device) {
	fileEntries, err := d.ListCDs()
	if err != nil {
		fmt.Printf("unable to fetch CD list: %v\n", err)
		os.Exit(1)
	}

	fmt.Printf("index,name,size\n")

	for _, entry := range fileEntries {
		fmt.Printf("%d,%s,%s\n", entry.Index(), entry.Name(), humanize.IBytes(entry.Size()))
	}
}

func setCD(d *toolbox.Device, idx int) {
	err := d.SetCDByIndex(idx)
	if err != nil {
		fmt.Printf("unable to set CD index: %v\n", err)
		os.Exit(1)
	}
}

func main() {
	device := flag.String("dev", "/dev/sr0", "the ODE device")
	index := flag.Int("index", -1, "the index to set")
	flag.Parse()

	d, err := toolbox.Open(*device)
	if err != nil {
		fmt.Printf("unable to open device: %v\n", err)
		os.Exit(1)
	}
	defer d.Close()

	if *index >= 0 {
		setCD(d, *index)
	} else {
		listCDs(d)
	}

}