From 2d994dec8d2b3dd0df563ef18bfc0a50a5523e49 Mon Sep 17 00:00:00 2001 From: Zellyn Hunter Date: Thu, 8 Dec 2016 22:18:09 -0500 Subject: [PATCH] Make applesoft cmd one file, create supermon cmd --- cmd/applesoft.go | 67 ++++++++++++++++++++++++++++++++++++++++++++++- cmd/decode.go | 68 ------------------------------------------------ cmd/nakedos.go | 18 +++++++++++++ 3 files changed, 84 insertions(+), 69 deletions(-) delete mode 100644 cmd/decode.go create mode 100644 cmd/nakedos.go diff --git a/cmd/applesoft.go b/cmd/applesoft.go index 081a593..cc0a02f 100644 --- a/cmd/applesoft.go +++ b/cmd/applesoft.go @@ -2,7 +2,15 @@ package cmd -import "github.com/spf13/cobra" +import ( + "fmt" + "os" + + "github.com/spf13/cobra" + "github.com/zellyn/diskii/lib/basic" + "github.com/zellyn/diskii/lib/basic/applesoft" + "github.com/zellyn/diskii/lib/helpers" +) // applesoftCmd represents the applesoft command var applesoftCmd = &cobra.Command{ @@ -25,3 +33,60 @@ func init() { // is called directly, e.g.: // applesoftCmd.Flags().BoolP("toggle", "t", false, "Help message for toggle") } + +// ----- applesoft decode commane ------------------------------------------- + +var location uint16 // flag for starting location in memory +var rawControlCodes bool // flag for whether to skip escaping control codes + +// decodeCmd represents the decode command +var decodeCmd = &cobra.Command{ + Use: "decode filename", + Short: "convert a binary applesoft program to a LISTing", + Long: ` +decode converts a binary Applesoft program to a text LISTing. + +Examples: +decode filename # read filename +decode - # read stdin`, + Run: func(cmd *cobra.Command, args []string) { + if err := runDecode(args); err != nil { + fmt.Fprintln(os.Stderr, err.Error()) + os.Exit(-1) + } + }, +} + +func init() { + applesoftCmd.AddCommand(decodeCmd) + + // Here you will define your flags and configuration settings. + + // Cobra supports Persistent Flags which will work for this command + // and all subcommands, e.g.: + // decodeCmd.PersistentFlags().String("foo", "", "A help for foo") + + decodeCmd.Flags().Uint16VarP(&location, "location", "l", 0x801, "Starting program location in memory") + decodeCmd.Flags().BoolVarP(&rawControlCodes, "raw", "r", false, "Print raw control codes (no escaping)") +} + +// runDecode performs the actual decode logic. +func runDecode(args []string) error { + if len(args) != 1 { + return fmt.Errorf("decode expects one argument: the filename (or - for stdin)") + } + contents, err := helpers.FileContentsOrStdIn(args[0]) + if err != nil { + return err + } + listing, err := applesoft.Decode(contents, location) + if err != nil { + return err + } + if rawControlCodes { + os.Stdout.WriteString(listing.String()) + } else { + os.Stdout.WriteString(basic.ChevronControlCodes(listing.String())) + } + return nil +} diff --git a/cmd/decode.go b/cmd/decode.go deleted file mode 100644 index 8025ce5..0000000 --- a/cmd/decode.go +++ /dev/null @@ -1,68 +0,0 @@ -// Copyright © 2016 Zellyn Hunter - -package cmd - -import ( - "fmt" - "os" - - "github.com/spf13/cobra" - "github.com/zellyn/diskii/lib/basic" - "github.com/zellyn/diskii/lib/basic/applesoft" - "github.com/zellyn/diskii/lib/helpers" -) - -var location uint16 // flag for starting location in memory -var rawControlCodes bool // flag for whether to skip escaping control codes - -// decodeCmd represents the decode command -var decodeCmd = &cobra.Command{ - Use: "decode filename", - Short: "convert a binary applesoft program to a LISTing", - Long: ` -decode converts a binary Applesoft program to a text LISTing. - -Examples: -decode filename # read filename -decode - # read stdin`, - Run: func(cmd *cobra.Command, args []string) { - if err := runDecode(args); err != nil { - fmt.Fprintln(os.Stderr, err.Error()) - os.Exit(-1) - } - }, -} - -func init() { - applesoftCmd.AddCommand(decodeCmd) - - // Here you will define your flags and configuration settings. - - // Cobra supports Persistent Flags which will work for this command - // and all subcommands, e.g.: - // decodeCmd.PersistentFlags().String("foo", "", "A help for foo") - - decodeCmd.Flags().Uint16VarP(&location, "location", "l", 0x801, "Starting program location in memory") - decodeCmd.Flags().BoolVarP(&rawControlCodes, "raw", "r", false, "Print raw control codes (no escaping)") -} - -// runDecode performs the actual decode logic. -func runDecode(args []string) error { - if len(args) != 1 { - return fmt.Errorf("decode expects one argument: the filename (or - for stdin)") - } - contents, err := helpers.FileContentsOrStdIn(args[0]) - if err != nil { - return err - } - listing, err := applesoft.Decode(contents, location) - if err != nil { - return err - } - if rawControlCodes { - os.Stdout.WriteString(listing.String()) - } else { - os.Stdout.WriteString(basic.ChevronControlCodes(listing.String())) - } - return nil -} diff --git a/cmd/nakedos.go b/cmd/nakedos.go new file mode 100644 index 0000000..692bbd7 --- /dev/null +++ b/cmd/nakedos.go @@ -0,0 +1,18 @@ +// Copyright © 2016 Zellyn Hunter + +package cmd + +import "github.com/spf13/cobra" + +// nakedosCmd represents the nakedos command +var nakedosCmd = &cobra.Command{ + Use: "nakedos", + Short: "work with NakedOS disks", + Long: `diskii nakedos contains the subcommands useful for working +with NakedOS (and Super-Mon) disks`, + Aliases: []string{"supermon"}, +} + +func init() { + RootCmd.AddCommand(nakedosCmd) +}