Skip to content

Commit a88ff06

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

File tree

8 files changed

+232
-17
lines changed

8 files changed

+232
-17
lines changed

Makefile

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,13 @@
1-
# Сборка проекта
1+
# Собирает бинарный файл в bin/hexlet-path-size
22
build:
33
go build -o bin/hexlet-path-size ./cmd/hexlet-path-size
44

5+
# Устанавливает собранный бинарник в GOPATH или GOBIN, чтобы его можно было запускать из любого места.
6+
install: build
7+
go install ./cmd/hexlet-path-size
8+
59
# Запуск линтера
6-
run:
10+
lint:
711
golangci-lint run
812

913
# Запуск линтера

README.md

Lines changed: 35 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,35 @@
1-
### 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)
1+
# go-project-242
2+
3+
## Description
4+
This is a disk size analysis program that allows you to get information about occupied and free space.
5+
6+
## Hexlet tests and linter status:
7+
[![Actions Status](https://github.com/alexvitayu/go-project-242/actions/workflows/hexlet-check.yml/badge.svg)](https://github.com/alexvitayu/go-project-242/actions)
8+
9+
## Requirements
10+
- Go 1.24
11+
- Make
12+
- golangci-lint
13+
14+
## Build and Setup (for global use)
15+
git clone https://github.com/alexvitayu/go-project-242.git
16+
cd go-project-242
17+
make build
18+
## for make install make sure that you have GOPATH or GOBIN set up in your PATH
19+
## to discover this just run 'echo $PATH', 'echo $GOPATH', 'echo $GOBIN'
20+
make install
21+
22+
## Run linter
23+
make lint
24+
25+
## Run tests
26+
make test
27+
28+
## Help
29+
hexlet-path-size -h --help
30+
31+
## Run the application from the terminal
32+
hexlet-path-size
33+
34+
## Follolw the link to watch how to install and use this application:
35+
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)