-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Updated the README.md file Updated .gitignore to include files
- Loading branch information
Showing
13 changed files
with
1,053 additions
and
18 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,18 +1,29 @@ | ||
# Exclude everything | ||
* | ||
# If you prefer the allow list template instead of the deny list, see community template: | ||
# https://github.com/github/gitignore/blob/main/community/Golang/Go.AllowList.gitignore | ||
# | ||
# Binaries for programs and plugins | ||
*.exe | ||
*.exe~ | ||
*.dll | ||
*.so | ||
*.dylib | ||
|
||
# Allow the .gitignore itself to be tracked | ||
!.gitignore | ||
# Test binary, built with `go test -c` | ||
*.test | ||
|
||
# Include the .vscode directory and its contents | ||
!.vscode/ | ||
!.vscode/** | ||
!makefiles/ | ||
!makefiles/** | ||
!.github/ | ||
!.github/** | ||
# Output of the go coverage tool, specifically when used with LiteIDE | ||
.codacy-coverage/ | ||
coverage* | ||
report* | ||
lint* | ||
|
||
# (Optionally) Include any other specific files you want | ||
!README.md | ||
!LICENSE | ||
!generate_config.sh | ||
# Dependency directories (remove the comment below to include it) | ||
vendor/ | ||
|
||
# Go workspace file | ||
go.work | ||
go.work.sum | ||
|
||
# vscode | ||
.vscode/ | ||
dist/ |
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 |
---|---|---|
@@ -0,0 +1,70 @@ | ||
export GO111MODULE=on | ||
GOOS := $(shell go env GOOS) | ||
VERSION := $(shell git describe --tags --always) | ||
BUILD_FLAGS := -ldflags="-X 'main.version=$(VERSION)'" | ||
# update to main app path | ||
APP_PATH := .\mass-code-parser.go | ||
|
||
# determins the variables based on GOOS | ||
ifeq ($(GOOS), windows) | ||
RM = del /Q | ||
HOME = $(shell echo %USERPROFILE%) | ||
CONFIG_PATH = $(subst ,,$(HOME)\.golangci.yaml) | ||
OUTPUT_PATH = C:\cli-tools | ||
else | ||
RM = rm -f | ||
HOME = $(shell echo $$HOME) | ||
CONFIG_PATH = $(HOME)/.golangci.yaml | ||
OUTPUT_PATH = /usr/local/bin | ||
endif | ||
|
||
check-quality: | ||
@make tidy | ||
@make fmt | ||
@make vet | ||
#@make lint | ||
|
||
lint: | ||
@make fmt | ||
@make vet | ||
golangci-lint run --config="$(CONFIG_PATH)" ./... | ||
|
||
vet: | ||
go vet ./... | ||
|
||
fmt: | ||
go fmt ./... | ||
|
||
tidy: | ||
go mod tidy | ||
|
||
update-packages: | ||
go get -u all | ||
|
||
update-common: | ||
go get github.com/ondrovic/common@latest | ||
|
||
test: | ||
make tidy | ||
go test -v -timeout 10m ./... -coverprofile=unit.coverage.out || (echo "Tests failed. See report.json for details." && exit 1) | ||
|
||
coverage: | ||
make test | ||
go tool cover -html=coverage.out -o coverage.html | ||
|
||
build: | ||
go build $(BUILD_FLAGS) -o $(OUTPUT_PATH) $(APP_PATH) | ||
|
||
all: | ||
make check-quality | ||
make test | ||
make build | ||
|
||
clean: | ||
go clean | ||
$(RM) *coverage* | ||
$(RM) *report* | ||
$(RM) *lint* | ||
|
||
vendor: | ||
go mod vendor |
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 |
---|---|---|
@@ -0,0 +1,14 @@ | ||
project: | ||
goreleaser.yaml: | ||
project_name: | ||
✔ replace PLACEHOLDER with actual name @done(24-08-27 12:44) | ||
env: | ||
GO_MAIN_PATH: | ||
✔ replace PLACEHOLDER with actual path @done(24-08-27 12:44) | ||
readme.md: | ||
✔ update based on relevant project info @done(24-08-27 12:51) | ||
testing: | ||
☐ write tests | ||
.github: | ||
workflows: | ||
☐ verify everythign is setup |
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 |
---|---|---|
@@ -0,0 +1,98 @@ | ||
package cmd | ||
|
||
import ( | ||
"fmt" | ||
"os" | ||
"runtime" | ||
|
||
"masscode-parser/internal/utils" | ||
|
||
"github.com/ondrovic/common/utils/formatters" | ||
"github.com/spf13/cobra" | ||
"github.com/spf13/viper" | ||
) | ||
|
||
var rootCmd = &cobra.Command{ | ||
Use: "mass-code-parser <path-to-db.json> [flags]", | ||
Short: "Parse and export MassCode database", | ||
Long: `A tool to parse and export MassCode database in various formats.`, | ||
Args: cobra.ExactArgs(1), | ||
RunE: run, | ||
} | ||
|
||
func init() { | ||
rootCmd.Flags().BoolP("output", "o", false, "Export results to a file") | ||
rootCmd.Flags().StringP("output-path", "p", "", "Path for the output file (without extension)") | ||
rootCmd.Flags().StringP("output-type", "t", "txt", "Output type: text, html, or json") | ||
|
||
viper.BindPFlags(rootCmd.Flags()) | ||
} | ||
|
||
func Execute() { | ||
if err := rootCmd.Execute(); err != nil { | ||
// fmt.Println(err) | ||
// os.Exit(1) | ||
return | ||
} | ||
} | ||
|
||
func run(cmd *cobra.Command, args []string) error { | ||
filePath := args[0] | ||
if !utils.FileExists(filePath) { | ||
return fmt.Errorf("file '%s' does not exist", filePath) | ||
} | ||
|
||
outputFlag := viper.GetBool("output") | ||
outputPath := viper.GetString("output-path") | ||
outputType := viper.GetString("output-type") | ||
|
||
if outputFlag { | ||
if outputPath == "" { | ||
outputPath = "mass_code_export" | ||
} | ||
outputPath = utils.EnsureCorrectExtension(outputPath, outputType) | ||
// correct outputPath formatting | ||
outputPath = formatters.FormatPath(outputPath, runtime.GOOS) | ||
|
||
fmt.Printf("Output will be saved to: %s\n", outputPath) | ||
} | ||
|
||
db, err := utils.ParseDatabase(filePath) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
fmt.Println("Parsed MassCode database successfully") | ||
fmt.Printf("Found %d folders and %d snippets\n\n", len(db.Folders), len(db.Snippets)) | ||
|
||
folderMap := utils.BuildFolderMap(db.Folders) | ||
outputData := utils.ProcessSnippets(db.Snippets, folderMap, db.Tags) | ||
|
||
var output string | ||
switch outputType { | ||
case "text": | ||
output, err = utils.GenerateTextOutput(outputData) | ||
case "html": | ||
output, err = utils.GenerateHTMLOutput(outputData) | ||
case "json": | ||
output, err = utils.GenerateJSONOutput(outputData) | ||
default: | ||
return fmt.Errorf("unsupported output type: %s", outputType) | ||
} | ||
|
||
if err != nil { | ||
return fmt.Errorf("error generating output: %v", err) | ||
} | ||
|
||
if outputFlag { | ||
err := os.WriteFile(outputPath, []byte(output), 0644) | ||
if err != nil { | ||
return fmt.Errorf("error writing to output file: %v", err) | ||
} | ||
fmt.Printf("Results exported to %s\n", outputPath) | ||
} else { | ||
fmt.Println(output) | ||
} | ||
|
||
return nil | ||
} |
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 |
---|---|---|
@@ -0,0 +1,43 @@ | ||
module masscode-parser | ||
|
||
go 1.23.0 | ||
|
||
require ( | ||
github.com/ondrovic/common v0.1.24 | ||
github.com/spf13/cobra v1.8.1 | ||
github.com/spf13/viper v1.19.0 | ||
) | ||
|
||
require ( | ||
atomicgo.dev/cursor v0.2.0 // indirect | ||
atomicgo.dev/keyboard v0.2.9 // indirect | ||
atomicgo.dev/schedule v0.1.0 // indirect | ||
github.com/containerd/console v1.0.4 // indirect | ||
github.com/fsnotify/fsnotify v1.7.0 // indirect | ||
github.com/gookit/color v1.5.4 // indirect | ||
github.com/hashicorp/hcl v1.0.0 // indirect | ||
github.com/inconshreveable/mousetrap v1.1.0 // indirect | ||
github.com/lithammer/fuzzysearch v1.1.8 // indirect | ||
github.com/magiconair/properties v1.8.7 // indirect | ||
github.com/mattn/go-runewidth v0.0.16 // indirect | ||
github.com/mitchellh/mapstructure v1.5.0 // indirect | ||
github.com/pelletier/go-toml/v2 v2.2.2 // indirect | ||
github.com/pterm/pterm v0.12.79 // indirect | ||
github.com/rivo/uniseg v0.4.7 // indirect | ||
github.com/sagikazarmark/locafero v0.4.0 // indirect | ||
github.com/sagikazarmark/slog-shim v0.1.0 // indirect | ||
github.com/sourcegraph/conc v0.3.0 // indirect | ||
github.com/spf13/afero v1.11.0 // indirect | ||
github.com/spf13/cast v1.6.0 // indirect | ||
github.com/spf13/pflag v1.0.5 // indirect | ||
github.com/subosito/gotenv v1.6.0 // indirect | ||
github.com/xo/terminfo v0.0.0-20220910002029-abceb7e1c41e // indirect | ||
go.uber.org/atomic v1.9.0 // indirect | ||
go.uber.org/multierr v1.9.0 // indirect | ||
golang.org/x/exp v0.0.0-20230905200255-921286631fa9 // indirect | ||
golang.org/x/sys v0.24.0 // indirect | ||
golang.org/x/term v0.23.0 // indirect | ||
golang.org/x/text v0.17.0 // indirect | ||
gopkg.in/ini.v1 v1.67.0 // indirect | ||
gopkg.in/yaml.v3 v3.0.1 // indirect | ||
) |
Oops, something went wrong.