diff --git a/.golangci.yaml b/.golangci.yaml new file mode 100644 index 0000000..f52f79d --- /dev/null +++ b/.golangci.yaml @@ -0,0 +1,5 @@ +run: + timeout: 5m + skip-dirs: + - dist + - test \ No newline at end of file diff --git a/.vscode/extensions.json b/.vscode/extensions.json new file mode 100644 index 0000000..e9525d2 --- /dev/null +++ b/.vscode/extensions.json @@ -0,0 +1,9 @@ +{ + // See https://go.microsoft.com/fwlink/?LinkId=827846 to learn about workspace recommendations. + // Extension identifier format: ${publisher}.${name}. Example: vscode.csharp + + // List of extensions which should be recommended for users of this workspace. + "recommendations": [ + "golang.go" + ] +} \ No newline at end of file diff --git a/.vscode/settings.json b/.vscode/settings.json new file mode 100644 index 0000000..4b0c116 --- /dev/null +++ b/.vscode/settings.json @@ -0,0 +1,5 @@ +{ + "go.lintTool": "golangci-lint", + "editor.formatOnSave": true, + "editor.defaultFormatter": "golang.go" +} \ No newline at end of file diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md new file mode 100644 index 0000000..3ededd1 --- /dev/null +++ b/CONTRIBUTING.md @@ -0,0 +1,40 @@ +# Contributing + +Pull requests are welcome. + +For major changes, please open an issue first to discuss what you would like to change. + +## Installation + +In order to build the application, you first need to [get Go CLI](https://go.dev/doc/install). + +The project was built using Go version `go1.19.1 windows/amd64`. If you are on a different version and experiencing any issues, please submit an issue regarding that. + +To build a binary or executable, run: + +``` +git clone https://github.com/devils2ndself/SSGo.git +cd SSGO +go build ssgo.go +``` +Or `go install` to install globally. + +## Formatting + +Anytime you perform changes that you want to contribute, please make sure the code is formatted appropriately. + +> Use `gofmt -s -w .` in order to format all code according to Go standards. + +## Linting + +We use [GoLangCI-Lint](https://golangci-lint.run/) in order to lint SSGo. You can see installation guide [here](https://golangci-lint.run/usage/install/). + +Linting is a part of a successful PR, so please make sure your code passes it. + +> Use `golangci-lint run` in order to lint-check all code in the directory. + +## IDE Integrations + +### VS Code + +It is recommended to install `golang.go` extension. This extension allows for automatic linting and on-save formatting. \ No newline at end of file diff --git a/README.md b/README.md index 40dc75f..61fc511 100644 --- a/README.md +++ b/README.md @@ -5,20 +5,6 @@ Lets you generate HTML files from either a single `.txt` file or multiple `.txt` Preview of generated HTML is available at https://devils2ndself.github.io/SSGo. -## Installation - -In order to build the application, you first need to [get Go CLI](https://go.dev/doc/install). - -To build a binary or executable, run: - -``` -git clone https://github.com/devils2ndself/SSGo.git -cd SSGO -go build ssgo.go -``` -Or `go install` to install globally. - - ## Usage - `ssgo --input [in] --output [out]` - Generate HTML from .txt or .md file at `in` path (can be a single .txt or .md file, or directory) to `out` path. @@ -65,9 +51,7 @@ These feaures are supported for files with an extension of '.md' ## Contributing -Pull requests are welcome. For major changes, please open an issue first to discuss what you would like to change. - -> Please make sure to update tests as appropriate. +Please see [CONTRIBUTING.md](CONTRIBUTING.md). ## License [MIT](https://choosealicense.com/licenses/mit/) diff --git a/ssgo.go b/ssgo.go index d9b0554..6b1db39 100644 --- a/ssgo.go +++ b/ssgo.go @@ -12,11 +12,11 @@ const version string = "0.4" func main() { var ( - input string = "" - output string = utils.DefaultOutput - displayHelp bool = false - displayVersion bool = false - config string = "" + input string = "" + output string = utils.DefaultOutput + displayHelp bool = false + displayVersion bool = false + config string = "" ) // Flag initialization @@ -34,7 +34,7 @@ func main() { } else { if config != "" { utils.ProcessConfig(config) - }else if input != "" { + } else if input != "" { utils.ProcessInput(input, output) } else if displayHelp { utils.PrintHelp() @@ -44,4 +44,4 @@ func main() { fmt.Println("Invalid call. Use 'ssgo [-h | --help]' for available commands.") } } -} \ No newline at end of file +} diff --git a/utils/help.go b/utils/help.go index 246701e..204eb83 100644 --- a/utils/help.go +++ b/utils/help.go @@ -3,9 +3,9 @@ package utils import "fmt" const ( - InputHelpMessage string = "Path to a .txt / .md file OR a folder containing .txt / .md files to be turned into HTML" - OutputHelpMessage string = "Optional. Additionaly changes the output path of generated HTML" - HelpHelpMessage string = "Display detailed help message" + InputHelpMessage string = "Path to a .txt / .md file OR a folder containing .txt / .md files to be turned into HTML" + OutputHelpMessage string = "Optional. Additionaly changes the output path of generated HTML" + HelpHelpMessage string = "Display detailed help message" VersionHelpMessage string = "Display installed version of SSGo" ConfigHelpMessage string = "Path to a .json file containing SSGo configuration options" ) @@ -20,4 +20,4 @@ func PrintHelp() { fmt.Println("\n\t[-v | --version] \t- " + HelpHelpMessage) fmt.Println("\t[-h | --help] \t- " + VersionHelpMessage) fmt.Println("\t[-c | --config] \t- " + ConfigHelpMessage) -} \ No newline at end of file +} diff --git a/utils/html-generation.go b/utils/html-generation.go index 4876466..6f13a3d 100644 --- a/utils/html-generation.go +++ b/utils/html-generation.go @@ -13,8 +13,8 @@ import ( const ( beforeTitleHTML string = "\n\n\n\n\n" - afterTitleHTML string = "\n\n\n\n" - closingHTML string = "\n\n" + afterTitleHTML string = "\n\n\n\n" + closingHTML string = "\n\n" ) // Takes path to .txt file as an input, reads it, and creates name.html in output folder @@ -54,7 +54,7 @@ func GenerateHTML(input string, output string, name string) { } } else { - // + // txtFile, err := os.Open(input) if err != nil { log.Fatal(err) @@ -130,7 +130,7 @@ func GenerateHTML(input string, output string, name string) { } paragraphOpen = false } - + // If last read line was a paragraph delimiter, write opening

first if !paragraphOpen && paragraphDelimiterFound { text = "

" + text @@ -141,7 +141,7 @@ func GenerateHTML(input string, output string, name string) { if werr != nil { log.Fatal("Error writing to new file!") } - + } else { paragraphDelimiterFound = true } @@ -163,4 +163,4 @@ func GenerateHTML(input string, output string, name string) { } writer.Flush() } -} \ No newline at end of file +} diff --git a/utils/input-processing.go b/utils/input-processing.go index 12c0ed7..4cbc6ba 100644 --- a/utils/input-processing.go +++ b/utils/input-processing.go @@ -10,8 +10,8 @@ import ( ) type File struct { - path string "" - name string "" + path string "" + name string "" } // Takes path to .json file, reads it, and calls ProcessInput using contained options @@ -30,7 +30,11 @@ func ProcessConfig(config string) { }{ Output: "dist", } - json.Unmarshal(configFile, &options) + + jsonErr := json.Unmarshal(configFile, &options) + if jsonErr != nil { + log.Fatal(jsonErr) + } // Call ProcessInput using config file options ProcessInput(options.Input, options.Output) @@ -55,7 +59,7 @@ func ProcessInput(input string, output string) { fmt.Println("Looking for .txt / .md files in the directory...") // Walks through all elements in the directory - filepath.Walk(input, func(path string, info os.FileInfo, err error) error { + walkErr := filepath.Walk(input, func(path string, info os.FileInfo, err error) error { if err != nil { log.Fatalf(err.Error()) } @@ -72,6 +76,9 @@ func ProcessInput(input string, output string) { } return nil }) + if walkErr != nil { + log.Fatal(walkErr) + } // If there is at least 1 .txt file if len(files) != 0 { @@ -104,8 +111,8 @@ func ProcessInput(input string, output string) { // Returns split name and extension of a filename func getNameAndExt(basename string) (string, string) { var ( - ext string = filepath.Ext(basename) - name string = strings.TrimSuffix(basename, ext) + ext string = filepath.Ext(basename) + name string = strings.TrimSuffix(basename, ext) ) return name, ext } @@ -144,4 +151,4 @@ func prepareOutput(output string) { log.Fatal(err) } } -} \ No newline at end of file +} diff --git a/utils/settings.go b/utils/settings.go index ee52a69..ceed16f 100644 --- a/utils/settings.go +++ b/utils/settings.go @@ -7,4 +7,4 @@ const DefaultOutput string = "dist" var AcceptedInputFileTypes = map[string]bool{ ".txt": true, ".md": true, -} \ No newline at end of file +}