-
-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Move business logic to separate package (#11)
- Loading branch information
Showing
14 changed files
with
91 additions
and
97 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
/* | ||
Copyright © 2023 NAME HERE <EMAIL ADDRESS> | ||
Copyright © 2023 Maciej Tatarski [email protected] | ||
*/ | ||
|
||
// Package cmd represents the command line interface of the application | ||
|
@@ -8,6 +8,7 @@ package cmd | |
import ( | ||
"fmt" | ||
|
||
"framed/pkg/ext" | ||
"os" | ||
"strconv" | ||
|
||
|
@@ -29,26 +30,26 @@ framed capture --output ./framed.yaml --name my-project | |
depthStr := cmd.Flag("depth").Value.String() | ||
depth, err := strconv.Atoi(depthStr) | ||
if err != nil { | ||
print("🚨 Invalid depth value: ", depthStr) | ||
ext.PrintOut("🚨 Invalid depth value: ", depthStr) | ||
os.Exit(1) | ||
} | ||
print("📝 Name:", name+"\n") | ||
ext.PrintOut("📝 Name:", name+"\n") | ||
|
||
// capture subdirectories | ||
subdirs := captureSubDirs(".", depth) | ||
print("📂 Directories:", fmt.Sprintf("%v", len(subdirs))) | ||
subdirs := ext.CaptureSubDirs(".", depth) | ||
ext.PrintOut("📂 Directories:", fmt.Sprintf("%v", len(subdirs))) | ||
|
||
// capture files | ||
files := captureAllFiles(".", depth) | ||
print("📄 Files:", fmt.Sprintf("%v", len(files))) | ||
files := ext.CaptureAllFiles(".", depth) | ||
ext.PrintOut("📄 Files:", fmt.Sprintf("%v", len(files))) | ||
|
||
// capture patterns | ||
patterns := captureRequiredPatterns(".", depth) | ||
print("🔁 Patterns:", fmt.Sprintf("%v", len(patterns))) | ||
patterns := ext.CaptureRequiredPatterns(".", depth) | ||
ext.PrintOut("🔁 Patterns:", fmt.Sprintf("%v", len(patterns))) | ||
|
||
// export config | ||
exportConfig(name, output, subdirs, files, patterns) | ||
print("\n✅ Exported to file: ", output) | ||
ext.ExportConfig(name, output, subdirs, files, patterns) | ||
ext.PrintOut("\n✅ Exported to file: ", output) | ||
}, | ||
} | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,13 @@ | ||
/* | ||
Copyright © 2023 NAME HERE <EMAIL ADDRESS> | ||
Copyright © 2023 Maciej Tatarski [email protected] | ||
*/ | ||
|
||
// Package cmd represents the command line interface of the application | ||
package cmd | ||
|
||
import ( | ||
"framed/pkg/ext" | ||
|
||
"github.com/spf13/cobra" | ||
) | ||
|
||
|
@@ -23,11 +25,11 @@ framed create --template ./framed.yaml --files true | |
createFiles := cmd.Flag("files").Value.String() == "true" | ||
|
||
// read config | ||
_, dirList := readConfig(path) | ||
_, dirList := ext.ReadConfig(path) | ||
|
||
// create directories | ||
for _, dir := range dirList { | ||
createDir(dir.Path) | ||
ext.CreateDir(dir.Path) | ||
} | ||
|
||
// create files | ||
|
@@ -37,7 +39,7 @@ framed create --template ./framed.yaml --files true | |
continue | ||
} | ||
for _, file := range *dir.Files { | ||
createFile(dir.Path, file) | ||
ext.CreateFile(dir.Path, file) | ||
} | ||
} | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,13 @@ | ||
/* | ||
Copyright © 2023 NAME HERE <EMAIL ADDRESS> | ||
Copyright © 2023 Maciej Tatarski [email protected] | ||
*/ | ||
|
||
// Package cmd represents the command line interface of the application | ||
package cmd | ||
|
||
import ( | ||
"fmt" | ||
"framed/pkg/ext" | ||
"io" | ||
"net/http" | ||
"os" | ||
|
@@ -45,11 +46,11 @@ framed import --example python --output ./python.yaml | |
} | ||
} | ||
|
||
print("✅ Saved to ==>", output) | ||
ext.PrintOut("✅ Saved to ==>", output) | ||
|
||
// try to load | ||
configTree, _ := readConfig(output) | ||
print("✅ Imported successfully ==>", configTree.Name) | ||
configTree, _ := ext.ReadConfig(output) | ||
ext.PrintOut("✅ Imported successfully ==>", configTree.Name) | ||
|
||
}, | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
/* | ||
Copyright © 2023 NAME HERE <EMAIL ADDRESS> | ||
Copyright © 2023 Maciej Tatarski [email protected] | ||
*/ | ||
|
||
// Package cmd represents the command line interface of the application | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,13 @@ | ||
/* | ||
Copyright © 2023 NAME HERE <EMAIL ADDRESS> | ||
Copyright © 2023 Maciej Tatarski [email protected] | ||
*/ | ||
|
||
// Package cmd represents the command line interface of the application | ||
package cmd | ||
|
||
import ( | ||
"fmt" | ||
"framed/pkg/ext" | ||
"os" | ||
"strings" | ||
|
||
|
@@ -25,13 +26,13 @@ framed verify --template ./framed.yaml | |
Run: func(cmd *cobra.Command, args []string) { | ||
path := cmd.Flag("template").Value.String() | ||
// read config | ||
_, dirList := readConfig(path) | ||
_, dirList := ext.ReadConfig(path) | ||
|
||
allGood := true | ||
// verify directories | ||
for _, dir := range dirList { | ||
if !dirExists(dir.Path) { | ||
print("❌ Directory not found ==>", dir.Path) | ||
if !ext.DirExists(dir.Path) { | ||
ext.PrintOut("❌ Directory not found ==>", dir.Path) | ||
allGood = false | ||
} | ||
|
||
|
@@ -41,27 +42,27 @@ framed verify --template ./framed.yaml | |
} | ||
|
||
// verify minCount and maxCount | ||
numFiles := countFiles(dir.Path) | ||
numFiles := ext.CountFiles(dir.Path) | ||
if numFiles < dir.MinCount { | ||
print("❌ Min count ("+fmt.Sprint(dir.MinCount)+") not met ==>", dir.Path) | ||
ext.PrintOut("❌ Min count ("+fmt.Sprint(dir.MinCount)+") not met ==>", dir.Path) | ||
allGood = false | ||
} | ||
if numFiles > dir.MaxCount { | ||
print("❌ Max count ("+fmt.Sprint(dir.MaxCount)+") exceeded ==>", dir.Path) | ||
ext.PrintOut("❌ Max count ("+fmt.Sprint(dir.MaxCount)+") exceeded ==>", dir.Path) | ||
allGood = false | ||
} | ||
|
||
// verify childrenAllowed | ||
if !dir.AllowChildren { | ||
if hasDirs(dir.Path) { | ||
print("❌ Children not allowed ==>", dir.Path) | ||
if ext.HasDirs(dir.Path) { | ||
ext.PrintOut("❌ Children not allowed ==>", dir.Path) | ||
allGood = false | ||
} | ||
} | ||
|
||
// verify maxDepth | ||
if checkDepth(dir.Path) > dir.MaxDepth { | ||
print("❌ Max depth exceeded ("+fmt.Sprint(dir.MaxDepth)+") ==>", dir.Path) | ||
if ext.CheckDepth(dir.Path) > dir.MaxDepth { | ||
ext.PrintOut("❌ Max depth exceeded ("+fmt.Sprint(dir.MaxDepth)+") ==>", dir.Path) | ||
allGood = false | ||
} | ||
|
||
|
@@ -84,33 +85,33 @@ framed verify --template ./framed.yaml | |
}, | ||
} | ||
|
||
func verifyFiles(dir SingleDir, allGood *bool) { | ||
func verifyFiles(dir ext.SingleDir, allGood *bool) { | ||
for _, file := range *dir.Files { | ||
if !fileExists(dir.Path + "/" + file) { | ||
print("❌ File not found ==>", dir.Path+"/"+file) | ||
if !ext.FileExists(dir.Path + "/" + file) { | ||
ext.PrintOut("❌ File not found ==>", dir.Path+"/"+file) | ||
*allGood = false | ||
} | ||
} | ||
} | ||
func verifyForbiddenPatterns(dir SingleDir, allGood *bool) { | ||
func verifyForbiddenPatterns(dir ext.SingleDir, allGood *bool) { | ||
for _, pattern := range *dir.ForbiddenPatterns { | ||
matched := matchPatternInDir(dir.Path, pattern) | ||
matched := ext.MatchPatternInDir(dir.Path, pattern) | ||
for _, match := range matched { | ||
print("❌ Forbidden pattern ("+pattern+") matched under ==>", dir.Path+"/"+match) | ||
ext.PrintOut("❌ Forbidden pattern ("+pattern+") matched under ==>", dir.Path+"/"+match) | ||
*allGood = false | ||
} | ||
} | ||
} | ||
|
||
func verifyAllowedPatterns(dir SingleDir, allGood *bool) { | ||
func verifyAllowedPatterns(dir ext.SingleDir, allGood *bool) { | ||
matchedCount := 0 | ||
for _, pattern := range *dir.AllowedPatterns { | ||
matched := matchPatternInDir(dir.Path, pattern) | ||
matched := ext.MatchPatternInDir(dir.Path, pattern) | ||
matchedCount += len(matched) | ||
} | ||
if matchedCount != countFiles(dir.Path) && len(*dir.AllowedPatterns) > 0 { | ||
if matchedCount != ext.CountFiles(dir.Path) && len(*dir.AllowedPatterns) > 0 { | ||
patternsString := strings.Join(*dir.AllowedPatterns, " ") | ||
print("❌ Not all files match required pattern ("+patternsString+") under ==>", dir.Path) | ||
ext.PrintOut("❌ Not all files match required pattern ("+patternsString+") under ==>", dir.Path) | ||
*allGood = false | ||
} | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,13 @@ | ||
/* | ||
Copyright © 2023 NAME HERE <EMAIL ADDRESS> | ||
Copyright © 2023 Maciej Tatarski [email protected] | ||
*/ | ||
|
||
// Package cmd represents the command line interface of the application | ||
package cmd | ||
|
||
import ( | ||
"framed/pkg/ext" | ||
|
||
"github.com/spf13/cobra" | ||
) | ||
|
||
|
@@ -21,10 +23,10 @@ framed visualize --template ./framed.yaml`, | |
path := cmd.Flag("template").Value.String() | ||
|
||
// read config | ||
_, dirList := readConfig(path) | ||
_, dirList := ext.ReadConfig(path) | ||
|
||
// visualize template | ||
visualizeTemplate(dirList) | ||
ext.VisualizeTemplate(dirList) | ||
}, | ||
} | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
/* | ||
Copyright © 2023 NAME HERE <EMAIL ADDRESS> | ||
Copyright © 2023 Maciej Tatarski [email protected] | ||
*/ | ||
package main | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.