mirror of
https://github.com/zellyn/diskii.git
synced 2025-02-16 10:32:10 +00:00
49 lines
1.3 KiB
Go
49 lines
1.3 KiB
Go
// Copyright © 2016 Zellyn Hunter <zellyn@gmail.com>
|
|
|
|
package cmd
|
|
|
|
import (
|
|
"fmt"
|
|
"os"
|
|
|
|
"github.com/zellyn/diskii/disk"
|
|
"github.com/zellyn/diskii/types"
|
|
)
|
|
|
|
type LsCmd struct {
|
|
Order string `kong:"default='auto',enum='auto,do,po',help='Logical-to-physical sector order.'"`
|
|
System string `kong:"default='auto',enum='auto,dos3',help='DOS system used for image.'"`
|
|
|
|
ShortNames bool `kong:"short='s',help='Whether to print short filenames (only makes a difference on Super-Mon disks).'"`
|
|
Image *os.File `kong:"arg,required,help='Disk/device image to read.'"`
|
|
Directory string `kong:"arg,optional,help='Directory to list (ProDOS only).'"`
|
|
}
|
|
|
|
func (l *LsCmd) Run(globals *types.Globals) error {
|
|
op, order, err := disk.OpenImage(l.Image, l.Order, l.System, globals)
|
|
if err != nil {
|
|
return fmt.Errorf("%w: %s", err, l.Image.Name())
|
|
}
|
|
if globals.Debug {
|
|
fmt.Fprintf(os.Stderr, "Opened disk with order %q, system %q\n", order, op.Name())
|
|
}
|
|
|
|
if l.Directory != "" {
|
|
if !op.HasSubdirs() {
|
|
return fmt.Errorf("Disks of type %q cannot have subdirectories", op.Name())
|
|
}
|
|
}
|
|
fds, err := op.Catalog(l.Directory)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
for _, fd := range fds {
|
|
if !l.ShortNames && fd.Fullname != "" {
|
|
fmt.Println(fd.Fullname)
|
|
} else {
|
|
fmt.Println(fd.Name)
|
|
}
|
|
}
|
|
return nil
|
|
}
|