feat: Add eject cmd
This commit is contained in:
@@ -0,0 +1,36 @@
|
||||
package cmd
|
||||
|
||||
import (
|
||||
"os"
|
||||
|
||||
"github.com/pojntfx/stfs/pkg/controllers"
|
||||
"github.com/spf13/cobra"
|
||||
"github.com/spf13/viper"
|
||||
)
|
||||
|
||||
var ejectCmd = &cobra.Command{
|
||||
Use: "eject",
|
||||
Aliases: []string{"e"},
|
||||
Short: "Eject the tape (tape only)",
|
||||
RunE: func(cmd *cobra.Command, args []string) error {
|
||||
if err := viper.BindPFlags(cmd.PersistentFlags()); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
f, err := os.OpenFile(viper.GetString(tapeFlag), os.O_RDONLY, os.ModeCharDevice)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
defer f.Close()
|
||||
|
||||
return controllers.EjectTape(f)
|
||||
},
|
||||
}
|
||||
|
||||
func init() {
|
||||
ejectCmd.PersistentFlags().StringP(tapeFlag, "t", "/dev/nst0", "Tape drive to get the current record from")
|
||||
|
||||
viper.AutomaticEnv()
|
||||
|
||||
rootCmd.AddCommand(ejectCmd)
|
||||
}
|
||||
@@ -11,7 +11,7 @@ import (
|
||||
|
||||
var tellCmd = &cobra.Command{
|
||||
Use: "tell",
|
||||
Aliases: []string{"tell"},
|
||||
Aliases: []string{"t"},
|
||||
Short: "Get the current record (tape only)",
|
||||
RunE: func(cmd *cobra.Command, args []string) error {
|
||||
if err := viper.BindPFlags(cmd.PersistentFlags()); err != nil {
|
||||
|
||||
Reference in New Issue
Block a user