Skip to content

Commit 609445e

Browse files
committed
Add demo.cast
1 parent 9f95357 commit 609445e

File tree

7 files changed

+195
-14
lines changed

7 files changed

+195
-14
lines changed

README.md

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,5 @@
11
### Hexlet tests and linter status:
2-
[![Actions Status](https://github.com/alexvitayu/go-project-242/actions/workflows/hexlet-check.yml/badge.svg)](https://github.com/alexvitayu/go-project-242/actions)
2+
[![Actions Status](https://github.com/alexvitayu/go-project-242/actions/workflows/hexlet-check.yml/badge.svg)](https://github.com/alexvitayu/go-project-242/actions)
3+
4+
### Follolw the link to watch how to install and use this application:
5+
https://asciinema.org/a/X0tSI1g2hWZAqzIo5zlSv3vzz

bin/hexlet-path-size

-554 Bytes
Binary file not shown.

cmd/hexlet-path-size/main.go

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
package main
22

33
import (
4-
goproject242 "code"
4+
"code"
55
"context"
66
"fmt"
77
"log"
@@ -11,10 +11,11 @@ import (
1111
)
1212

1313
func main() {
14+
fmt.Println("Hello from Hexlet!")
1415
cmd := &cli.Command{
1516
UseShortOptionHandling: true,
1617
Name: "hexlet-path-size",
17-
Usage: "print size of a file or directory;",
18+
Usage: "print size of a file or directory; supports -r (recursive), -H (human-readable), -a (include hidden)",
1819
Flags: []cli.Flag{
1920
&cli.BoolFlag{
2021
Name: "human",
@@ -40,11 +41,12 @@ func main() {
4041
h := cmd.Bool("human")
4142
a := cmd.Bool("all")
4243
r := cmd.Bool("recursive")
43-
size, err := goproject242.GetPathSize(path, r, h, a)
44+
size, err := code.GetPathSize(path, r, h, a)
4445
if err != nil {
4546
log.Println(err.Error())
4647
}
47-
fmt.Println(size)
48+
str := fmt.Sprintf("%v\t%s", size, path)
49+
fmt.Println(str)
4850
return nil
4951
},
5052
}

demo.cast

Lines changed: 175 additions & 0 deletions
Large diffs are not rendered by default.

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
module code
22

3-
go 1.24.4
3+
go 1.24
44

55
require (
66
github.com/stretchr/testify v1.10.0

path_size.go

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package goproject242
1+
package code
22

33
import (
44
"errors"
@@ -18,7 +18,8 @@ func GetPathSize(path string, recursive, human, all bool) (string, error) {
1818
if err != nil {
1919
return "", fmt.Errorf("%w", err)
2020
}
21-
return fmt.Sprintf("%v\t%s", FormatSize(sum, human), path), nil
21+
//return fmt.Sprintf("%v\t%s", FormatSize(sum, human), path), nil
22+
return fmt.Sprintf("%v", FormatSize(sum, human)), nil
2223

2324
}
2425

@@ -72,7 +73,7 @@ func FormatSize(size int64, human bool) string {
7273
case len(str) <= 3:
7374
return fmt.Sprintf("%vB", size)
7475
case len(str) > 3 && len(str) <= 6:
75-
return fmt.Sprintf("%.1fKB", float64(size)/math.Pow(10, 3))
76+
return fmt.Sprintf("%.1fKB", float64(size)/1000)
7677
case len(str) >= 7 && len(str) < 10:
7778
return fmt.Sprintf("%.1fMB", float64(size)/math.Pow(10, 6))
7879
case len(str) >= 10 && len(str) < 13:

path_size_test.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package goproject242
1+
package code
22

33
import (
44
"errors"
@@ -20,7 +20,7 @@ var testCases = []struct {
2020
{
2121
name: "Path-file",
2222
path_file: "testdata/text.txt",
23-
expect: "23B\ttestdata/text.txt",
23+
expect: "23B",
2424
err: nil,
2525
human: true,
2626
all: true,
@@ -29,7 +29,7 @@ var testCases = []struct {
2929
{
3030
name: "Path-directory",
3131
path_file: "testdata",
32-
expect: "9153B\ttestdata",
32+
expect: "9153B",
3333
err: nil,
3434
human: false,
3535
all: true,
@@ -56,7 +56,7 @@ var testCases = []struct {
5656
{
5757
name: "Without hidden files",
5858
path_file: "testdata",
59-
expect: "8939B\ttestdata",
59+
expect: "8939B",
6060
err: nil,
6161
human: false,
6262
all: false,
@@ -65,7 +65,7 @@ var testCases = []struct {
6565
{
6666
name: "Recursive",
6767
path_file: "testdata",
68-
expect: "6947251B\ttestdata",
68+
expect: "6947251B",
6969
err: nil,
7070
human: false,
7171
all: true,

0 commit comments

Comments
 (0)