Skip to content

Commit

Permalink
chore(cli): add -no-hints flag
Browse files Browse the repository at this point in the history
  • Loading branch information
saffage committed Jun 20, 2024
1 parent 0304e8c commit 39ea22e
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 10 deletions.
22 changes: 18 additions & 4 deletions config/flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,10 @@ var (
// Enable debug information.
FlagDebug bool

// Enable debug information.
FlagNoHints bool

// Dump the checker state after checking a module.
FlagDumpCheckerState bool

// Display a program AST of the specified Jet module and exit.
Expand All @@ -36,9 +40,7 @@ const (
ActionShowHelp Action = iota
ActionError
ActionCompileToC
ActionGenerate // TODO remove

ActionDefault = ActionGenerate
ActionNonCmd
)

func ParseArgs(args []string) ([]string, Action) {
Expand Down Expand Up @@ -70,7 +72,7 @@ func ParseArgs(args []string) ([]string, Action) {
if errors.Is(err, flag.ErrHelp) {
return nil, ActionShowHelp
}
return cmdJet.Args(), ActionDefault
return cmdJet.Args(), ActionNonCmd
}
}

Expand All @@ -84,6 +86,12 @@ func init() {
false,
"Enable debug information",
)
cmdJet.BoolVar(
&FlagNoHints,
"no-hints",
false,
"Disable the compiler hints. Hints will still be enabled if the -debug flag is set",
)
cmdJet.BoolVar(
&FlagDumpCheckerState,
"dump-checker-state",
Expand Down Expand Up @@ -128,6 +136,12 @@ func init() {
false,
"Enable compiler's debug output",
)
cmdC.BoolVar(
&FlagNoHints,
"no-hints",
false,
"Disable the compiler hints. Hints will still be enabled if the -debug flag is set",
)
cmdC.BoolVar(
&CFlagBuild,
"build",
Expand Down
14 changes: 12 additions & 2 deletions internal/jet/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,23 @@ import (

func ProcessArgs(args []string) {
args, action := config.ParseArgs(args)
report.IsDebug = config.FlagDebug

switch {
case config.FlagDebug:
report.Level = report.KindDebug

case config.FlagNoHints:
report.Level = report.KindWarning

default:
report.Level = report.KindHint
}

switch action {
case config.ActionShowHelp:
// Nothing to do

case config.ActionDefault:
case config.ActionNonCmd:
if len(args) == 0 {
report.Errorf("expected filename")
return
Expand Down
4 changes: 2 additions & 2 deletions internal/report/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ var UseColors = true
// Specifies whether to output the actual code from the file.
var ShowLine = true

// Specifies whether to output debug messages.
var IsDebug = false
// Specifies a level of messages.
var Level = KindNote

// Reporter is an interface that is used to make the report prettier/clearer.
//
Expand Down
4 changes: 2 additions & 2 deletions internal/report/report.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ func display(kind Kind, message string) {
}

func reportInternal(kind Kind, tag, message string) {
if kind == KindDebug && !IsDebug {
if kind < Level {
return
}

Expand All @@ -43,7 +43,7 @@ func reportInternal(kind Kind, tag, message string) {
}

func reportAtInternal(kind Kind, tag string, start, end token.Pos, message string) {
if kind == KindDebug && !IsDebug {
if kind < Level {
return
}

Expand Down

0 comments on commit 39ea22e

Please sign in to comment.