mirror of
https://github.com/zellyn/diskii.git
synced 2026-04-20 02:16:28 +00:00
Initial implementation of NakeOS/Super-Mon GetFile
This commit is contained in:
@@ -12,12 +12,13 @@ import (
|
||||
_ "github.com/zellyn/diskii/lib/supermon"
|
||||
)
|
||||
|
||||
// catCmd represents the cat command, used to catalog a disk or
|
||||
// catalogCmd represents the cat command, used to catalog a disk or
|
||||
// directory.
|
||||
var catCmd = &cobra.Command{
|
||||
Use: "cat",
|
||||
Short: "print a list of files",
|
||||
Long: `Catalog a disk or subdirectory.`,
|
||||
var catalogCmd = &cobra.Command{
|
||||
Use: "catalog",
|
||||
Aliases: []string{"cat", "ls"},
|
||||
Short: "print a list of files",
|
||||
Long: `Catalog a disk or subdirectory.`,
|
||||
Run: func(cmd *cobra.Command, args []string) {
|
||||
if err := runCat(args); err != nil {
|
||||
fmt.Fprintln(os.Stderr, err.Error())
|
||||
@@ -27,7 +28,7 @@ var catCmd = &cobra.Command{
|
||||
}
|
||||
|
||||
func init() {
|
||||
RootCmd.AddCommand(catCmd)
|
||||
RootCmd.AddCommand(catalogCmd)
|
||||
}
|
||||
|
||||
// runCat performs the actual catalog logic.
|
||||
+56
@@ -0,0 +1,56 @@
|
||||
// Copyright © 2016 Zellyn Hunter <zellyn@gmail.com>
|
||||
|
||||
package cmd
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"os"
|
||||
|
||||
"github.com/spf13/cobra"
|
||||
"github.com/zellyn/diskii/lib/disk"
|
||||
_ "github.com/zellyn/diskii/lib/dos33"
|
||||
_ "github.com/zellyn/diskii/lib/supermon"
|
||||
)
|
||||
|
||||
// dumpCmd represents the dump command, used to dump the raw contents
|
||||
// of a file.
|
||||
var dumpCmd = &cobra.Command{
|
||||
Use: "dump",
|
||||
Short: "dump the raw contents of a file",
|
||||
Long: `Dump the raw contents of a file.
|
||||
|
||||
dump disk-image.dsk HELLO
|
||||
`,
|
||||
Run: func(cmd *cobra.Command, args []string) {
|
||||
if err := runDump(args); err != nil {
|
||||
fmt.Fprintln(os.Stderr, err.Error())
|
||||
os.Exit(-1)
|
||||
}
|
||||
},
|
||||
}
|
||||
|
||||
func init() {
|
||||
RootCmd.AddCommand(dumpCmd)
|
||||
}
|
||||
|
||||
// runDump performs the actual dump logic.
|
||||
func runDump(args []string) error {
|
||||
if len(args) != 2 {
|
||||
return fmt.Errorf("dump expects a disk image filename, and a filename")
|
||||
}
|
||||
sd, err := disk.Open(args[0])
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
op, err := disk.OperatorFor(sd)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
file, err := op.GetFile(args[1])
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
// TODO(zellyn): allow writing to files
|
||||
os.Stdout.Write(file.Data)
|
||||
return nil
|
||||
}
|
||||
Reference in New Issue
Block a user