Documentation ¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
View Source
var CatCmd = &cobra.Command{ Use: "cat", Short: "Concatenate and display file contents", Args: cobra.ArbitraryArgs, Run: func(cmd *cobra.Command, args []string) { number, _ := cmd.Flags().GetBool("number") numberNonBlank, _ := cmd.Flags().GetBool("number-nonblank") squeezeBlank, _ := cmd.Flags().GetBool("squeeze-blank") if len(args) > 1 && args[len(args)-2] == "mx" { mergeFiles(args[:len(args)-2], args[len(args)-1]) } else { for _, file := range args { displayFile(file, number, numberNonBlank, squeezeBlank) } } }, }
View Source
var CdCmd = &cobra.Command{ Use: "cd", Short: "Change the current working directory", Args: cobra.ExactArgs(1), Run: func(cmd *cobra.Command, args []string) { targetDir := args[0] if targetDir == ".." { currentDir, err := os.Getwd() if err != nil { log.Fatalf("Error getting current directory: %v", err) } targetDir = filepath.Dir(currentDir) } err := os.Chdir(targetDir) if err != nil { log.Fatalf("Error changing directory: %v", err) } newDir, err := os.Getwd() if err != nil { log.Fatalf("Error getting new directory: %v", err) } fmt.Println("Directory changed successfully") fmt.Println(newDir) }, }
View Source
var LsCmd = &cobra.Command{ Use: "ls", Short: "List directory contents", Run: func(cmd *cobra.Command, args []string) { dir, _ := cmd.Flags().GetString("directory") showHidden, _ := cmd.Flags().GetBool("a") appendSlashToDir, _ := cmd.Flags().GetBool("F") sortByTime, _ := cmd.Flags().GetBool("t") listInode, _ := cmd.Flags().GetBool("i") humanReadable, _ := cmd.Flags().GetBool("V") listFiles(dir, showHidden, appendSlashToDir, sortByTime, listInode, humanReadable) }, }
View Source
var MkdirCmd = &cobra.Command{ Use: "mkdir [dirName]", Short: "Create a new file", Long: `The touch command creates a new file with the given dir_Name.`, Run: func(cmd *cobra.Command, args []string) { if len(args) == 1 { Dir_Maker(args[0]) } else if len(args) > 1 { for _, i := range args[:] { Dir_Maker(i) } } }, }
View Source
var PwdCmd = &cobra.Command{ Use: "pwd", Short: "Print the current working directory", Run: func(cmd *cobra.Command, args []string) { dir, err := os.Getwd() checkError(err, "getting current working directory") fmt.Println(dir) }, }
Command to print the current working directory
View Source
var RmCmd = &cobra.Command{ Use: "rm", Short: "Remove files or directories", Run: func(cmd *cobra.Command, args []string) { if len(args) < 1 { fmt.Println("Usage: rm [flags] [file ...]") return } interactive, _ := cmd.Flags().GetBool("interactive") confirmAll, _ := cmd.Flags().GetBool("confirm-all") recursive, _ := cmd.Flags().GetBool("recursive") force, _ := cmd.Flags().GetBool("force") if interactive { for _, file := range args { RemoveI_Method(file) } } else if confirmAll { fmt.Print("Remove all specified files? (y/n): ") reader := bufio.NewReader(os.Stdin) char, _, err := reader.ReadRune() if err != nil { fmt.Println("Error reading input:", err) return } if char == 'Y' || char == 'y' { for _, file := range args { removeFile(file) } } else { fmt.Println("Files not removed") } } else if recursive { if len(args) != 1 { fmt.Println("Usage: rm -r [directory]") return } removeDir(args[0]) } else if force { for _, file := range args { removeFile(file) } } else { for _, file := range args { removeFile(file) } } }, }
View Source
var TouchCmd = &cobra.Command{ Use: "touch [filename]", Short: "Create a new file", Long: `The touch command creates a new file with the given filename.`, Run: func(cmd *cobra.Command, args []string) { if len(args) == 1 { File_Maker(args[0]) } else if len(args) > 1 { for _, i := range args[:] { File_Maker(i) } } }, }
Functions ¶
func File_Maker ¶
func File_Maker(fileName string)
func InitCommands ¶
func RemoveI_Method ¶
func RemoveI_Method(file string)
Types ¶
type FileTimeStruct ¶
Click to show internal directories.
Click to hide internal directories.