Skip to content

Commit

Permalink
Applying 3rd round review comments
Browse files Browse the repository at this point in the history
  • Loading branch information
RawanMostafa08 committed Sep 9, 2024
1 parent 444e33e commit c9d6041
Show file tree
Hide file tree
Showing 6 changed files with 19 additions and 23 deletions.
15 changes: 7 additions & 8 deletions cmd/tree/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,12 @@ func main() {
var maxDepth int
flag.IntVar(&maxDepth, "L", 1, "Print files and directories up to 'L' levels of depth")
flag.Parse()
if len(flag.Args()) == 0 {
currDir, err := os.Getwd()
if err != nil {
log.Fatal("Error reaching the current directory")
}
internal.Tree(currDir, 0, maxDepth)
} else {
internal.Tree(flag.Args()[0], 0, maxDepth)
dir, err := os.Getwd()
if err != nil {
log.Fatal("Error reaching the current directory")
}
if len(flag.Args()) != 0 {
dir = flag.Args()[0]
}
internal.Tree(dir, 0, maxDepth)
}
6 changes: 4 additions & 2 deletions cmd/wc/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package main
import (
"bufio"
"flag"
"fmt"
"log"
"os"
"strings"
Expand All @@ -24,7 +25,8 @@ func main() {
if len(flag.Args()) == 0 {
log.Fatal("No file argument passed to the command")
}
data, err := os.ReadFile(flag.Args()[0])
file:=flag.Args()[0]
data, err := os.ReadFile(file)
if err != nil {
log.Fatal("Error in reading the file")
}
Expand All @@ -40,5 +42,5 @@ func main() {
if err != nil {
log.Fatal("Error in scanning std input")
}

fmt.Println(file)
}
2 changes: 0 additions & 2 deletions internal/tail.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,8 @@ import (
func Tail(scanner *bufio.Scanner, n int) error {

scanner.Split(bufio.ScanLines)
count := 0
lines := make([]string, 0)
for scanner.Scan() {
count++
lines = append(lines, string(scanner.Bytes()))
}

Expand Down
5 changes: 3 additions & 2 deletions internal/tree.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"fmt"
"log"
"os"
"path/filepath"
"strings"
)

Expand All @@ -18,8 +19,8 @@ func Tree(directoryPath string, depth int, maxDepth int) {
if err != nil {
log.Fatalf("Error reading items in: %s", directoryPath)
}
pathParts := strings.Split(directoryPath, "/")
formattedPrint(pathParts[len(pathParts)-1], depth)
lastPathElement := filepath.Base(directoryPath)
formattedPrint(lastPathElement, depth)

for _, item := range items {
if depth+1 > maxDepth {
Expand Down
1 change: 0 additions & 1 deletion internal/wc.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,5 @@ func Wc(scanner *bufio.Scanner, isLines bool, isWords bool, isChars bool) error
if isChars {
fmt.Printf("%d ", charsCount)
}
fmt.Print("\n")
return scanner.Err()
}
13 changes: 5 additions & 8 deletions internal/yes.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,11 @@ import (
)

func Yes(inputs []string) {
output := "y"
if len(inputs) > 0 {
input := strings.Join(inputs, " ")
for {
fmt.Println(input)
}
} else {
for {
fmt.Println("y")
}
output = strings.Join(inputs, " ")
}
for {
fmt.Println(output)
}
}

0 comments on commit c9d6041

Please sign in to comment.