We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 882e0f4 commit edfa9baCopy full SHA for edfa9ba
cli-files/go-ls/cmd/root.go
@@ -11,10 +11,20 @@ var rootCmd = &cobra.Command{
11
Use: "go-ls",
12
Short: "go-ls is a re-implementation of the ls command",
13
RunE: func(cmd *cobra.Command, args []string) error {
14
- files, err := os.ReadDir(".")
+ // By default, ls the current directory
15
+ dir := "."
16
+ // If an argument was passed, use the first as our directory
17
+ if len(args) > 0 {
18
+ dir = args[0]
19
+ }
20
+
21
+ // Read this directory to get a list of files
22
+ // https://pkg.go.dev/os#ReadDir
23
+ files, err := os.ReadDir(dir)
24
if err != nil {
25
return err
26
}
27
+ // Iterate through each file in the directory, printing the file name
28
for _, file := range files {
29
fmt.Println(file.Name())
30
0 commit comments