Skip to content

Commit

Permalink
add casemode to cli
Browse files Browse the repository at this point in the history
  • Loading branch information
maddyblue committed Jul 3, 2019
1 parent 74d6450 commit 8bf48db
Showing 1 changed file with 5 additions and 0 deletions.
5 changes: 5 additions & 0 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ var (
flagPrintWidth = flag.Int("print-width", 60, "line length where sqlfmt will try to wrap")
flagUseSpaces = flag.Bool("use-spaces", false, "indent with spaces instead of tabs")
flagTabWidth = flag.Int("tab-width", 4, "number of spaces per indentation level")
flagCasemode = flag.String("casemode", "upper", "keyword casing, can be: upper, lower, title, spongebob")
flagNoSimplify = flag.Bool("no-simplify", false, "don't simplify the output")
flagAlign = flag.Bool("align", false, "right-align keywords")
flagStmts = flag.StringArray("stmt", nil, "instead of reading from stdin, specify statements as arguments")
Expand Down Expand Up @@ -99,6 +100,9 @@ func runCmd() error {
if *flagTabWidth < 1 {
return errors.Errorf("tab width must be > 0: %d", *flagTabWidth)
}
if *flagCasemode != "" && caseModes[*flagCasemode] == nil {
return errors.Errorf("unknown casemode: %s", *flagCasemode)
}

sl := *flagStmts
if len(sl) == 0 {
Expand All @@ -115,6 +119,7 @@ func runCmd() error {
cfg.TabWidth = *flagTabWidth
cfg.Simplify = !*flagNoSimplify
cfg.Align = tree.PrettyNoAlign
cfg.Case = caseModes[*flagCasemode]
if *flagAlign {
cfg.Align = tree.PrettyAlignAndDeindent
}
Expand Down

0 comments on commit 8bf48db

Please sign in to comment.