Skip to content

Commit

Permalink
chore: make pkg structure work with GoReleaser
Browse files Browse the repository at this point in the history
Signed-off-by: Joseph Kato <joseph@jdkato.io>
  • Loading branch information
jdkato committed Jan 7, 2021
1 parent 58f1834 commit 6b3c281
Show file tree
Hide file tree
Showing 14 changed files with 68 additions and 65 deletions.
3 changes: 1 addition & 2 deletions .gitignore
Expand Up @@ -25,8 +25,7 @@ fixtures/formats/Sphinx/_build/
.bundle
.vagrant

cmd/vale/flag_closed.go
rule/grammar_closed.go
internal/cli/flag_closed.go



38 changes: 0 additions & 38 deletions cmd/vale/flag.go

This file was deleted.

17 changes: 9 additions & 8 deletions cmd/vale/main.go
Expand Up @@ -6,6 +6,7 @@ import (
"io/ioutil"
"os"

"github.com/errata-ai/vale/v2/internal/cli"
"github.com/errata-ai/vale/v2/internal/core"
"github.com/errata-ai/vale/v2/internal/lint"
)
Expand Down Expand Up @@ -76,17 +77,17 @@ func doLint(args []string, l *lint.Linter, glob string) ([]*core.File, error) {
}

func handleError(err error) {
ShowError(err, flags.Output, os.Stderr)
cli.ShowError(err, cli.Flags.Output, os.Stderr)
os.Exit(2)
}

func main() {
v := flag.Bool("v", false, "prints current version")
flag.Parse()

config, err := core.NewConfig(&flags)
config, err := core.NewConfig(&cli.Flags)
if err != nil {
ShowError(err, flags.Output, os.Stderr)
cli.ShowError(err, cli.Flags.Output, os.Stderr)
}

if *v {
Expand All @@ -98,7 +99,7 @@ func main() {
argc := len(args)

if argc == 0 && !stat() {
printIntro()
cli.PrintIntro()
}

if err := validateFlags(config); err != nil {
Expand All @@ -108,7 +109,7 @@ func main() {
}

if argc > 0 {
cmd, exists := actions[args[0]]
cmd, exists := cli.Actions[args[0]]
if exists {
if err = cmd(args[1:], config); err != nil {
os.Exit(2)
Expand All @@ -122,15 +123,15 @@ func main() {
handleError(err)
}

linted, err := doLint(args, linter, flags.Glob)
linted, err := doLint(args, linter, cli.Flags.Glob)
if err != nil {
handleError(err)
}

hasErrors, err := PrintAlerts(linted, config)
hasErrors, err := cli.PrintAlerts(linted, config)
if err != nil {
handleError(err)
} else if hasErrors && !flags.NoExit {
} else if hasErrors && !cli.Flags.NoExit {
os.Exit(1)
}

Expand Down
2 changes: 1 addition & 1 deletion cmd/vale/color.go → internal/cli/color.go
@@ -1,4 +1,4 @@
package main
package cli

import (
"fmt"
Expand Down
11 changes: 6 additions & 5 deletions cmd/vale/command.go → internal/cli/command.go
@@ -1,4 +1,4 @@
package main
package cli

import (
"flag"
Expand All @@ -12,21 +12,22 @@ var commandInfo = map[string]string{
"ls-config": "Print the current configuration to stdout and exit.",
}

var actions = map[string]func(args []string, cfg *core.Config) error{
// Actions are the available CLI commands.
var Actions = map[string]func(args []string, cfg *core.Config) error{
"ls-config": printConfig,
"dc": printConfig,
"help": printUsage,
}

func printConfig(args []string, cfg *core.Config) error {
cfg, err := core.NewConfig(&flags)
cfg, err := core.NewConfig(&Flags)
if err != nil {
ShowError(err, flags.Output, os.Stderr)
ShowError(err, Flags.Output, os.Stderr)
}

err = core.From("ini", cfg)
if err != nil {
ShowError(err, flags.Output, os.Stderr)
ShowError(err, Flags.Output, os.Stderr)
}

fmt.Println(cfg.String())
Expand Down
2 changes: 1 addition & 1 deletion cmd/vale/common.go → internal/cli/common.go
@@ -1,4 +1,4 @@
package main
package cli

import (
"sort"
Expand Down
2 changes: 1 addition & 1 deletion cmd/vale/custom.go → internal/cli/custom.go
@@ -1,4 +1,4 @@
package main
package cli

import (
"io/ioutil"
Expand Down
2 changes: 1 addition & 1 deletion cmd/vale/error.go → internal/cli/error.go
@@ -1,4 +1,4 @@
package main
package cli

import (
"errors"
Expand Down
40 changes: 40 additions & 0 deletions internal/cli/flag.go
@@ -0,0 +1,40 @@
package cli

import (
"flag"

"github.com/errata-ai/vale/v2/internal/core"
"github.com/mholt/archiver/v3"
)

// Flags are the user-defined CLI flags.
var Flags core.CLIFlags

var zip archiver.Unarchiver

func init() {
flag.StringVar(&Flags.Sources, "sources", "", "config files to load")
flag.StringVar(&Flags.Glob, "glob", "*",
`A glob pattern (e.g., --glob='*.{md,txt}).'`)
flag.StringVar(&Flags.Path, "config", "",
`A file path (e.g., --config='some/file/path/.vale.ini').`)
flag.StringVar(&Flags.AlertLevel, "minAlertLevel", "",
`Lowest alert level to display (e.g., --minAlertLevel=error).`)
flag.StringVar(&Flags.Output, "output", "CLI",
`Output style ("line", "JSON", or a template file).`)
flag.StringVar(&Flags.InExt, "ext", ".txt",
`Extension to associate with stdin (e.g., --ext=.md).`)

flag.BoolVar(&Flags.Wrap, "no-wrap", false, "Don't wrap CLI output.")
flag.BoolVar(&Flags.NoExit, "no-exit", false,
"Don't return a nonzero exit code on errors.")
flag.BoolVar(&Flags.Local, "mode-compat", false,
"prioritize local Vale configurations")
flag.BoolVar(&Flags.Sorted, "sort", false,
"sort files by their name in output")
flag.BoolVar(&Flags.Normalize, "normalize", false,
"replace each path separator with a slash ('/')")
flag.BoolVar(&Flags.Simple, "ignore-syntax", false,
"Lint all files line-by-line.")
flag.BoolVar(&Flags.Relative, "relative", false, "return relative paths")
}
2 changes: 1 addition & 1 deletion cmd/vale/funcs.go → internal/cli/funcs.go
@@ -1,4 +1,4 @@
package main
package cli

import (
"fmt"
Expand Down
8 changes: 4 additions & 4 deletions cmd/vale/info.go → internal/cli/info.go
@@ -1,4 +1,4 @@
package main
package cli

import (
"flag"
Expand All @@ -16,7 +16,7 @@ var exampleConfig = `StylesPath = a/path/to/your/styles
[*]
BasedOnStyles = Vale`

var intro = fmt.Sprintf(`vale - A command-line linter for prose [%s]
var intro = fmt.Sprintf(`vale - A command-line linter for prose.
%s: %s
%s
Expand All @@ -35,7 +35,6 @@ To get started, you'll need a configuration file (%s):
%s
See %s for more setup information.`,
aurora.Faint(version),
aurora.Bold("Usage"),

aurora.Faint("vale [options] [input...]"),
Expand Down Expand Up @@ -65,7 +64,8 @@ var hidden = []string{
"sources",
}

func printIntro() {
// PrintIntro shows basic usage / gettting started info.
func PrintIntro() {
fmt.Println(info)
os.Exit(0)
}
Expand Down
2 changes: 1 addition & 1 deletion cmd/vale/json.go → internal/cli/json.go
@@ -1,4 +1,4 @@
package main
package cli

import (
"fmt"
Expand Down
2 changes: 1 addition & 1 deletion cmd/vale/line.go → internal/cli/line.go
@@ -1,4 +1,4 @@
package main
package cli

import (
"fmt"
Expand Down
2 changes: 1 addition & 1 deletion cmd/vale/util.go → internal/cli/util.go
@@ -1,4 +1,4 @@
package main
package cli

import (
"encoding/json"
Expand Down

0 comments on commit 6b3c281

Please sign in to comment.