Skip to content

Commit

Permalink
add -with-indents flag
Browse files Browse the repository at this point in the history
  • Loading branch information
zelenin committed Dec 4, 2022
1 parent 6274ec3 commit 3531c81
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 5 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -55,5 +55,6 @@ Powershell:

Optional:
```powershell
-with-indents ^
-threads 3
```
19 changes: 14 additions & 5 deletions cmd/object-stream-converter/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,10 @@ const (
)

var (
pool *workerpool.Pool
outputDir string
pr *profiler.Profiler
pool *workerpool.Pool
outputDir string
withIndents bool
pr *profiler.Profiler
)

const typeField = "__type"
Expand All @@ -44,6 +45,8 @@ func main() {
inputDirPtr := flag.String("input", ".\\extract", "directory path")
outputDirPtr := flag.String("output", ".\\json", "directory path")
threadsPtr := flag.Int64("threads", defaultThreads, fmt.Sprintf("1-%d", maxThreads))
withIndentsPtr := flag.Bool("with-indents", false, "enable indents in json")
poolCapacityPtr := flag.Int64("pool-capacity", 1000, "pool capacity")
flag.Parse()

threads := *threadsPtr
Expand All @@ -52,6 +55,9 @@ func main() {
}
log.Printf("The number of threads is set to %d", threads)

withIndents = *withIndentsPtr
poolCapacity := *poolCapacityPtr

inputDir, err := filepath.Abs(filepath.Clean(*inputDirPtr))
if err != nil {
log.Fatalf("filepath.Abs: %s", err)
Expand All @@ -72,7 +78,7 @@ func main() {
log.Fatalf("MkdirAll: %s", err)
}

pool = workerpool.NewPool(threads, 1000)
pool = workerpool.NewPool(threads, poolCapacity)

go func() {
errorChan := pool.Errors()
Expand Down Expand Up @@ -215,7 +221,10 @@ func addTask(id int64, job Job) {
}

enc := json.NewEncoder(jf)
enc.SetIndent("", " ")

if withIndents {
enc.SetIndent("", " ")
}

err = enc.Encode(data)
if err != nil {
Expand Down

0 comments on commit 3531c81

Please sign in to comment.