Skip to content

Commit

Permalink
YAML format support for output results
Browse files Browse the repository at this point in the history
  • Loading branch information
aleksaan committed Jan 10, 2021
1 parent bfe18fd commit 362910e
Show file tree
Hide file tree
Showing 9 changed files with 295 additions and 71 deletions.
21 changes: 14 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,20 @@
# diskusage
diskusage is an utility to find top largest directories on the disk.

## !!! 2020.12.02: Version 2.2.0 is now avaliable !!!
## 5 TIMES FASTER NOW
## !!! 2021.10.01: Version 2.3.0 is now avaliable !!!
## SAVING RESULTS IN YAML FORMAT

```cmd
About:
github/aleksaan/diskusage, 2.2.0, Alexander Anufriev, 2020
github/aleksaan/diskusage, 2.3.0, Alexander Anufriev, 2021
Arguments:
path: d:\_appl\go\src\
limit: 20
units: <dynamic>
depth: 5
tofile: diskusage_out.txt
toTextFile: diskusage_out.txt
toYamlFile: diskusage_out.yaml
Results:
1.| PATH: github.com | SIZE: 316.65 Mb | DEPTH: 1
Expand Down Expand Up @@ -92,7 +93,8 @@ analyzer:
printer:
limit: 20
units: Gb
tofile: diskusage_out.txt
toTextFile: diskusage_out.txt
toYamlFile: diskusage_out.yaml
```
where:
```yaml
Expand Down Expand Up @@ -122,9 +124,14 @@ Fixed scale values: b, Kb, Mb, Gb, Tb, Pb.
You can use "units" in case you want to compare sizes afterward (optional).
```yaml
tofile: diskusage_out.txt
toTextFile: diskusage_out.txt
```
File name to save results. If value is empty file will not be created and you will see results in console window with prompt to exit at the end.
File name to save results in human readable format. If value is empty file will not be created and you will see results in console window with prompt to exit at the end.
```yaml
toYamlFile: diskusage_out.yaml
```
File name for saving results in YAML format for best compatibility with others programs.
Run ```diskusage.exe```
9 changes: 5 additions & 4 deletions config/component.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,9 @@ type AnalyzerConfig struct {

//PrinterConfig section
type PrinterConfig struct {
Limit *int `yaml:"limit,omitempty"`
Units *string `yaml:"units,omitempty"`
ToFile *string `yaml:"tofile,omitempty"`
Sort *string
Limit *int `yaml:"limit,omitempty"`
Units *string `yaml:"units,omitempty"`
ToTextFile *string `yaml:"toTextFile,omitempty"`
ToYamlFile *string `yaml:"toYamlFile,omitempty"`
Sort *string
}
4 changes: 3 additions & 1 deletion config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,5 +80,7 @@ func (c *Config) createDefaultConfigYamlFile() {
files.PrintEndOfLine(f)
fmt.Fprintf(f, " units:")
files.PrintEndOfLine(f)
fmt.Fprintf(f, " tofile: diskusage_out.txt")
fmt.Fprintf(f, " toTextFile: diskusage_out.txt")
files.PrintEndOfLine(f)
fmt.Fprintf(f, " toYamlFile: diskusage_out.yaml")
}
22 changes: 14 additions & 8 deletions config/default.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,12 @@ package config
import "os"

const (
defaultDepth = 5
defaultLimit = 20
defaultUnits = ""
defaultSort = "size_desc"
defaultToFile = ""
defaultDepth = 5
defaultLimit = 20
defaultUnits = ""
defaultSort = "size_desc"
defaultToTextFile = ""
defaultToYamlFile = ""
//DefaultToFile = "<no file>"
)

Expand All @@ -32,9 +33,14 @@ func (c *Config) setDefaultValues() {
c.Printer.Units = &u
}

if c.Printer.ToFile == nil {
u := defaultToFile
c.Printer.ToFile = &u
if c.Printer.ToTextFile == nil {
u := defaultToTextFile
c.Printer.ToTextFile = &u
}

if c.Printer.ToYamlFile == nil {
u := defaultToYamlFile
c.Printer.ToYamlFile = &u
}

if c.Printer.Sort == nil {
Expand Down
5 changes: 3 additions & 2 deletions diskusage_config.yaml
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
analyzer:
path: C:\
path: C:\_goworkspace\src\github.com\aleksaan\diskusage
depth: 5
printer:
limit: 20
units:
tofile: .\bin\diskusage_out_fast.txt
toTextFile: diskusage_out.txt
toYamlFile: diskusage_out.yaml
160 changes: 160 additions & 0 deletions diskusage_out.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,160 @@
- number: 0
path: ""
sizeInBytes: 25375380
isDir: true
isLink: false
depth: 1
adaptedSize: 24.199848175048828
adaptedUnit: Mb
- number: 0
path: ""
sizeInBytes: 25338551
isDir: true
isLink: false
depth: 2
adaptedSize: 24.164725303649902
adaptedUnit: Mb
- number: 0
path: ""
sizeInBytes: 15598063
isDir: true
isLink: false
depth: 1
adaptedSize: 14.875472068786621
adaptedUnit: Mb
- number: 0
path: ""
sizeInBytes: 11131946
isDir: true
isLink: false
depth: 3
adaptedSize: 10.616250991821289
adaptedUnit: Mb
- number: 0
path: ""
sizeInBytes: 11131946
isDir: false
isLink: false
depth: 4
adaptedSize: 10.616250991821289
adaptedUnit: Mb
- number: 0
path: ""
sizeInBytes: 10100361
isDir: true
isLink: false
depth: 3
adaptedSize: 9.632454872131348
adaptedUnit: Mb
- number: 0
path: ""
sizeInBytes: 10089545
isDir: false
isLink: false
depth: 4
adaptedSize: 9.622139930725098
adaptedUnit: Mb
- number: 0
path: ""
sizeInBytes: 3963718
isDir: true
isLink: false
depth: 1
adaptedSize: 3.7800960540771484
adaptedUnit: Mb
- number: 0
path: ""
sizeInBytes: 3925504
isDir: false
isLink: false
depth: 2
adaptedSize: 3.74365234375
adaptedUnit: Mb
- number: 0
path: ""
sizeInBytes: 3499008
isDir: false
isLink: false
depth: 1
adaptedSize: 3.3369140625
adaptedUnit: Mb
- number: 0
path: ""
sizeInBytes: 2386856
isDir: true
isLink: false
depth: 2
adaptedSize: 2.2762832641601562
adaptedUnit: Mb
- number: 0
path: ""
sizeInBytes: 2386856
isDir: false
isLink: false
depth: 3
adaptedSize: 2.2762832641601562
adaptedUnit: Mb
- number: 0
path: ""
sizeInBytes: 2349568
isDir: true
isLink: false
depth: 2
adaptedSize: 2.24072265625
adaptedUnit: Mb
- number: 0
path: ""
sizeInBytes: 2349568
isDir: false
isLink: false
depth: 3
adaptedSize: 2.24072265625
adaptedUnit: Mb
- number: 0
path: ""
sizeInBytes: 2236436
isDir: true
isLink: false
depth: 3
adaptedSize: 2.132831573486328
adaptedUnit: Mb
- number: 0
path: ""
sizeInBytes: 2236436
isDir: false
isLink: false
depth: 4
adaptedSize: 2.132831573486328
adaptedUnit: Mb
- number: 0
path: ""
sizeInBytes: 2215936
isDir: true
isLink: false
depth: 2
adaptedSize: 2.11328125
adaptedUnit: Mb
- number: 0
path: ""
sizeInBytes: 2215936
isDir: false
isLink: false
depth: 3
adaptedSize: 2.11328125
adaptedUnit: Mb
- number: 0
path: ""
sizeInBytes: 2031616
isDir: true
isLink: false
depth: 2
adaptedSize: 1.9375
adaptedUnit: Mb
- number: 0
path: ""
sizeInBytes: 2031616
isDir: false
isLink: false
depth: 3
adaptedSize: 1.9375
adaptedUnit: Mb
32 changes: 21 additions & 11 deletions files/files.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,17 +7,19 @@ import (

//TFile - struct for file object
type TFile struct {
RelativePath string
Name string
Size int64
IsDir bool
IsLink bool
LinkedDirPath string
Depth int
IsNotAccessible bool
IsNotAccessibleMessage string
AdaptedSize float64
AdaptedUnit string
Number int `yaml:"number"`
RelativePath string `yaml:"-"`
FullPath string `yaml:"path"`
Name string `yaml:"-"`
Size int64 `yaml:"sizeInBytes"`
IsDir bool `yaml:"isDir"`
IsLink bool `yaml:"isLink"`
LinkedDirPath string `yaml:"-"`
Depth int `yaml:"depth"`
IsNotAccessible bool `yaml:"-"`
IsNotAccessibleMessage string `yaml:"-"`
AdaptedSize float64 `yaml:"adaptedSize"`
AdaptedUnit string `yaml:"adaptedUnit"`
}

//TFiles - struct for files array object
Expand Down Expand Up @@ -69,3 +71,11 @@ func (files *TFiles) Sort(by string) {
sort.Sort(sizeAndNameSorter(*files))
}
}

//ComputeFullPathAndNumber - compute additional fields for files
func (files *TFiles) ComputeFullPathAndNumber(startPath string) {
for i, f := range *files {
f.FullPath = startPath + "\\" + f.RelativePath + f.Name
f.Number = i
}
}
5 changes: 2 additions & 3 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,12 @@ import (
func main() {
var cfg = config.Cfg


cfg.Load()
printer.Load()
printer.PrintAbout()
analyzer.Run()
printer.Run()
console.WaitExit(*config.Cfg.Printer.ToFile == "")
console.WaitExit(*config.Cfg.Printer.ToTextFile == "")
printer.Close()

}
Loading

0 comments on commit 362910e

Please sign in to comment.