-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add stubbed-out delete, supermon symbol encoding
- Loading branch information
Showing
7 changed files
with
203 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
// Copyright © 2016 Zellyn Hunter <[email protected]> | ||
|
||
package cmd | ||
|
||
import ( | ||
"fmt" | ||
"os" | ||
|
||
"github.com/spf13/cobra" | ||
"github.com/zellyn/diskii/lib/disk" | ||
_ "github.com/zellyn/diskii/lib/dos3" | ||
_ "github.com/zellyn/diskii/lib/supermon" | ||
) | ||
|
||
// deleteCmd represents the delete command, used to delete a file. | ||
var deleteCmd = &cobra.Command{ | ||
Use: "delete", | ||
Short: "delete a file", | ||
Long: `Delete a file. | ||
delete disk-image.dsk HELLO | ||
`, | ||
Run: func(cmd *cobra.Command, args []string) { | ||
if err := runDelete(args); err != nil { | ||
fmt.Fprintln(os.Stderr, err.Error()) | ||
os.Exit(-1) | ||
} | ||
}, | ||
} | ||
|
||
func init() { | ||
RootCmd.AddCommand(deleteCmd) | ||
} | ||
|
||
// runDelete performs the actual delete logic. | ||
func runDelete(args []string) error { | ||
if len(args) != 2 { | ||
return fmt.Errorf("delete 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 | ||
} | ||
deleted, err := op.Delete(args[1]) | ||
if err != nil { | ||
return err | ||
} | ||
if !deleted { | ||
// TODO(zellyn): implement -f flag to not warn on nonexistence. | ||
return fmt.Errorf("file %q not found", args[1]) | ||
} | ||
f, err := os.Create(args[0]) | ||
if err != nil { | ||
return err | ||
} | ||
_, err = sd.Write(f) | ||
if err != nil { | ||
return err | ||
} | ||
if err = f.Close(); err != nil { | ||
return err | ||
} | ||
return nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters