Skip to content

Commit

Permalink
Merge pull request #13 from rudychung/issue-12
Browse files Browse the repository at this point in the history
Added config option for #12
  • Loading branch information
devils2ndself authored Oct 6, 2022
2 parents 9db46d5 + 6d65600 commit de7d877
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 2 deletions.
6 changes: 5 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,11 @@ 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.
- `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.
`--output` is optional, the default out is `dist` folder in the current directory

- `ssgo --config [cfg]` - Uses the options from .json configuration file at `cfg` path to specify options.

- `ssgo --version` - Display installed version of SSGo

- `ssgo --help` - Display detailed help message
Expand All @@ -50,6 +52,8 @@ Also, please be aware that shorthand flags, like `-i`, take as the argument ever

- If `--output` is specified, the directory at path will not be erased like with `dist` folder. Just in case someone specifies `--output C:\...`

- If `--config' is specified, SSG options can be supplied through a .json configuration file instead of through the command-line.

### Markdown Features
These feaures are supported for files with an extension of '.md'

Expand Down
6 changes: 5 additions & 1 deletion ssgo.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,21 +19,25 @@ func main() {
output string = defaultOutput
displayHelp bool = false
displayVersion bool = false
config string = ""
)

// Flag initialization
flag.StringVarP(&input, "input", "i", "", utils.InputHelpMessage)
flag.StringVarP(&output, "output", "o", defaultOutput, utils.OutputHelpMessage)
flag.BoolVarP(&displayHelp, "help", "h", false, utils.HelpHelpMessage)
flag.BoolVarP(&displayVersion, "version", "v", false, utils.VersionHelpMessage)
flag.StringVarP(&config, "config", "c", "", utils.ConfigHelpMessage)

flag.Parse()

if len(os.Args) == 1 {
fmt.Println("Usage: ssgo -i [path] -o [out path]\nHelp: ssgo [-h | --help]")
os.Exit(1)
} else {
if input != "" {
if config != "" {
utils.ProcessConfig(config)
}else if input != "" {
utils.ProcessInput(input, output)
} else if displayHelp {
utils.PrintHelp()
Expand Down
24 changes: 24 additions & 0 deletions utils/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package utils

import (
"bufio"
"encoding/json"
"fmt"
"log"
"os"
Expand All @@ -27,6 +28,7 @@ const (
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"
)

func PrintHelp() {
Expand All @@ -39,6 +41,7 @@ func PrintHelp() {
fmt.Println("\t[-o | --output] [out path] \t- " + OutputHelpMessage)
fmt.Println("\n\t[-v | --version] \t- " + HelpHelpMessage)
fmt.Println("\t[-h | --help] \t- " + VersionHelpMessage)
fmt.Println("\t[-c | --config] \t- " + ConfigHelpMessage)
}


Expand Down Expand Up @@ -155,6 +158,27 @@ func ProcessInput(input string, output string) {
fmt.Println("Done! Check '" + output + "' directory to see generated HTML.")
}

// Takes path to .json file, reads it, and calls ProcessInput using contained options
func ProcessConfig(config string) {

// Read config .json file
configFile, err := os.ReadFile(config)
if err != nil {
log.Fatal(err)
}

// Assign json values to options struct
options := struct {
Input string `json:"input"`
Output string `json:"output"`
}{
Output: "dist",
}
json.Unmarshal(configFile, &options)

// Call ProcessInput using config file options
ProcessInput(options.Input, options.Output)
}

// Takes path to .txt file as an input, reads it, and creates name.html in output folder
func GenerateHTML(input string, output string, name string) {
Expand Down

0 comments on commit de7d877

Please sign in to comment.