Documentation
¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
View Source
var CatCmd = &cobra.Command{ Use: "cat", Short: "cat files", Long: `cat files`, Run: func(cmd *cobra.Command, args []string) { if len(args) == 0 { return } for _, fileToCat := range args { if files.Exists(fileToCat) { fh, err := os.Open(args[0]) if err != nil { fmt.Println(err) continue } defer fh.Close() io.Copy(os.Stdout, fh) } } }, }
CatCmd represents the cat command
View Source
var DownloadCmd = &cobra.Command{ Use: "download", Short: "A brief description of your command", Long: `A longer description that spans multiple lines and likely contains examples and usage of using your command. For example: Cobra is a CLI library for Go that empowers applications. This application is a tool to generate the needed files to quickly create a Cobra application.`, Run: func(cmd *cobra.Command, args []string) { for _, fileToGet := range args { parse, err := url.Parse(fileToGet) if err != nil { log.Println(err) continue } saveFile := filepath.Base(parse.Path) if files.Exists(saveFile) { fmt.Printf("File exists. Would you like to delete it? ") var input string fmt.Scanln(&input) if strings.ToLower(input)[0] == 'y' { os.Remove(saveFile) } } err = files.DownloadURL(parse, saveFile) if err != nil { log.Println(err) } } }, }
DownloadCmd represents the fetch command
View Source
var ListCmd = &cobra.Command{ Use: "ls", Short: "List files", Long: `List files`, Run: func(cmd *cobra.Command, args []string) { listPath := "." var err error if len(args) > 0 { listPath = args[0] } listPath, err = filepath.Abs(listPath) if err != nil { log.Println(err) } myFiles, err := files.GetFileInfo(listPath) if err != nil { fmt.Fprintf(os.Stderr, "Error: %v\n", err) os.Exit(1) } files.PrintFileList(myFiles) }, }
ListCmd represents the ls command
View Source
var RootCmd = &cobra.Command{ Use: "gnas", Short: "A cross platform shell like program with mini-programs", Long: `A cross platform shell like program with mini-programs`, Run: func(cmd *cobra.Command, args []string) { app := console.New("gnas") app.NewlineBefore = true app.NewlineAfter = true if len(ShellName) > 0 { app.SetPrintLogo(func(_ *console.Console) { fmt.Print(ShellBanner) }) } menu := app.ActiveMenu() setupPrompt(menu) hist, _ := embeddedHistory(".gnas-history") menu.AddHistorySource("local history", hist) menu.AddInterrupt(io.EOF, exitCtrlD) menu.SetCommands(func() *cobra.Command { return cmd }) app.Start() }, }
RootCmd represents the base command when called without any subcommands
View Source
var ServeCmd = &cobra.Command{ Use: "serve", Short: "A brief description of your command", Long: `A longer description that spans multiple lines and likely contains examples and usage of using your command. For example: Cobra is a CLI library for Go that empowers applications. This application is a tool to generate the needed files to quickly create a Cobra application.`, Run: func(cmd *cobra.Command, args []string) { dir, _ := cmd.Flags().GetString("dir") allowPut, _ := cmd.Flags().GetBool("put") if err := files.HTTPServer(ServerListener, dir, allowPut, UploadToken); err != nil { log.Println(err.Error()) } }, }
ServeCmd represents the serve command
View Source
var ServerListener = ":8000"
View Source
var ShellBanner = `` /* 732-byte string literal not displayed */
View Source
var ShellName = "GNAS"
View Source
var UploadCmd = &cobra.Command{ Use: "upload", Short: "A brief description of your command", Long: `A longer description that spans multiple lines and likely contains examples and usage of using your command. For example: Cobra is a CLI library for Go that empowers applications. This application is a tool to generate the needed files to quickly create a Cobra application.`, Run: func(cmd *cobra.Command, args []string) { remoteDir, _ := cmd.Flags().GetString("remote-dir") for _, fileToPut := range args { remoteFile := filepath.Clean(fileToPut) remoteDir := path.Clean(remoteDir) remotePath := path.Join(remoteDir, remoteFile) serverURL := fmt.Sprintf("%s/%s", UploadEndpoint, remotePath) err := files.UploadFile(serverURL, UploadToken, fileToPut) if err != nil { log.Println(err) } } }, }
UploadCmd represents the fetch command
View Source
var UploadEndpoint = UploadServer + ServerListener
View Source
var UploadServer = "http://127.0.0.1"
View Source
var UploadToken = "you should change this at build time"
Functions ¶
Types ¶
Click to show internal directories.
Click to hide internal directories.