set tracing on by default for the utility commands
This commit is contained in:
parent
a009c1918d
commit
aba563ab9a
@ -21,8 +21,9 @@ type checkOptions struct {
|
||||
// InputString specifies the input content as an inline string.
|
||||
InputString *string
|
||||
|
||||
// MaxTraceLength enables tracing when set to a positive integer.
|
||||
MaxTraceLength int
|
||||
// MaxTraceLength configures tracing when set to a positive integer. Non-positive values disable
|
||||
// tracing.
|
||||
MaxTraceLength *int
|
||||
}
|
||||
|
||||
// check parses input content against the provided syntax definition and fails if the input does not match.
|
||||
@ -41,7 +42,12 @@ func check(o checkOptions, stdin io.Reader, args ...string) error {
|
||||
}
|
||||
|
||||
defer finalizeInput()
|
||||
s := &treerack.Syntax{MaxTraceLength: o.MaxTraceLength}
|
||||
mtl := defaultMaxTraceLength
|
||||
if o.MaxTraceLength != nil {
|
||||
mtl = *o.MaxTraceLength
|
||||
}
|
||||
|
||||
s := &treerack.Syntax{MaxTraceLength: mtl}
|
||||
if err := s.ReadSyntax(syntax); err != nil {
|
||||
if terr := treerack.Trace(os.Stderr, err); terr != nil {
|
||||
err = errors.Join(err, terr)
|
||||
|
||||
@ -7,6 +7,8 @@ import (
|
||||
"os"
|
||||
)
|
||||
|
||||
const defaultMaxTraceLength = 36
|
||||
|
||||
type checkSyntaxOptions struct {
|
||||
|
||||
// Syntax specifies the filename of the syntax definition file.
|
||||
@ -15,8 +17,9 @@ type checkSyntaxOptions struct {
|
||||
// SyntaxString specifies the syntax as an inline string.
|
||||
SyntaxString *string
|
||||
|
||||
// MaxTraceLength enables tracing when set to a positive integer.
|
||||
MaxTraceLength int
|
||||
// MaxTraceLength configures tracing when set to a positive integer. Non-positive values disable
|
||||
// tracing.
|
||||
MaxTraceLength *int
|
||||
}
|
||||
|
||||
// checkSyntax validates a syntax definition. The syntax may be provided via a file path (using an option or a
|
||||
@ -28,7 +31,12 @@ func checkSyntax(o checkSyntaxOptions, stdin io.Reader, args ...string) error {
|
||||
}
|
||||
|
||||
defer finalize()
|
||||
s := &treerack.Syntax{MaxTraceLength: o.MaxTraceLength}
|
||||
mtl := defaultMaxTraceLength
|
||||
if o.MaxTraceLength != nil {
|
||||
mtl = *o.MaxTraceLength
|
||||
}
|
||||
|
||||
s := &treerack.Syntax{MaxTraceLength: mtl}
|
||||
if err := s.ReadSyntax(syntax); err != nil {
|
||||
if terr := treerack.Trace(os.Stderr, err); terr != nil {
|
||||
err = errors.Join(err, terr)
|
||||
|
||||
@ -12,14 +12,15 @@ func init() {
|
||||
docreflect.Register("main.checkOptions", "")
|
||||
docreflect.Register("main.checkOptions.Input", "Input specifies the filename of the input content to be validated.\n")
|
||||
docreflect.Register("main.checkOptions.InputString", "InputString specifies the input content as an inline string.\n")
|
||||
docreflect.Register("main.checkOptions.MaxTraceLength", "MaxTraceLength enables tracing when set to a positive integer.\n")
|
||||
docreflect.Register("main.checkOptions.MaxTraceLength", "MaxTraceLength configures tracing when set to a positive integer. Non-positive values disable\ntracing.\n")
|
||||
docreflect.Register("main.checkOptions.Syntax", "Syntax specifies the filename of the syntax definition file.\n")
|
||||
docreflect.Register("main.checkOptions.SyntaxString", "SyntaxString specifies the syntax as an inline string.\n")
|
||||
docreflect.Register("main.checkSyntax", "checkSyntax validates a syntax definition. The syntax may be provided via a file path (using an option or a\npositional argument), an inline string, or piped from standard input.\n\nfunc(o, stdin, args)")
|
||||
docreflect.Register("main.checkSyntaxOptions", "")
|
||||
docreflect.Register("main.checkSyntaxOptions.MaxTraceLength", "MaxTraceLength enables tracing when set to a positive integer.\n")
|
||||
docreflect.Register("main.checkSyntaxOptions.MaxTraceLength", "MaxTraceLength configures tracing when set to a positive integer. Non-positive values disable\ntracing.\n")
|
||||
docreflect.Register("main.checkSyntaxOptions.Syntax", "Syntax specifies the filename of the syntax definition file.\n")
|
||||
docreflect.Register("main.checkSyntaxOptions.SyntaxString", "SyntaxString specifies the syntax as an inline string.\n")
|
||||
docreflect.Register("main.defaultMaxTraceLength", "")
|
||||
docreflect.Register("main.errInvalidFilename", "")
|
||||
docreflect.Register("main.errMultipleInputs", "")
|
||||
docreflect.Register("main.errNoInput", "")
|
||||
@ -29,7 +30,7 @@ func init() {
|
||||
docreflect.Register("main.formatInline", "\nfunc(syntax, out, maxTraceLength)")
|
||||
docreflect.Register("main.formatOptions", "")
|
||||
docreflect.Register("main.formatOptions.InPlace", "InPlace specifies if an input file should be formatted in-place instead of printing the formatted\nresults to the standard output.\n")
|
||||
docreflect.Register("main.formatOptions.MaxTraceLength", "MaxTraceLength enables tracing when set to a positive integer.\n")
|
||||
docreflect.Register("main.formatOptions.MaxTraceLength", "MaxTraceLength configures tracing when set to a positive integer. Non-positive values disable\ntracing.\n")
|
||||
docreflect.Register("main.formatOptions.Syntax", "Syntax specifies the filename of the syntax definition file.\n")
|
||||
docreflect.Register("main.formatOptions.SyntaxString", "SyntaxString specifies the syntax as an inline string.\n")
|
||||
docreflect.Register("main.formatStdin", "\nfunc(in, out, maxTraceLength)")
|
||||
@ -37,7 +38,7 @@ func init() {
|
||||
docreflect.Register("main.generate", "generate generates Go code that can parse arbitrary input with the provided syntax, and can be used embedded\nin an application.\n\nThe syntax may be provided via a file path (using an option or a positional argument), an\ninline string, or piped from standard input.\n\nfunc(o, stdin, stdout, args)")
|
||||
docreflect.Register("main.generateOptions", "")
|
||||
docreflect.Register("main.generateOptions.Export", "Export determines whether the generated parse function is exported (visible outside its package).\n")
|
||||
docreflect.Register("main.generateOptions.MaxTraceLength", "MaxTraceLength enables tracing when set to a positive integer.\n")
|
||||
docreflect.Register("main.generateOptions.MaxTraceLength", "MaxTraceLength configures tracing when set to a positive integer. Non-positive values disable\ntracing.\n")
|
||||
docreflect.Register("main.generateOptions.PackageName", "PackageName specifies the package name for the generated code. Defaults to main.\n")
|
||||
docreflect.Register("main.generateOptions.Syntax", "Syntax specifies the filename of the syntax definition file.\n")
|
||||
docreflect.Register("main.generateOptions.SyntaxString", "SyntaxString specifies the syntax as an inline string.\n")
|
||||
@ -57,7 +58,7 @@ func init() {
|
||||
docreflect.Register("main.showOptions.Indent", "Indent specifies a custom indentation string for the output.\n")
|
||||
docreflect.Register("main.showOptions.Input", "Input specifies the filename of the input content to be validated.\n")
|
||||
docreflect.Register("main.showOptions.InputString", "InputString specifies the input content as an inline string.\n")
|
||||
docreflect.Register("main.showOptions.MaxTraceLength", "MaxTraceLength enables tracing when set to a positive integer.\n")
|
||||
docreflect.Register("main.showOptions.MaxTraceLength", "MaxTraceLength configures tracing when set to a positive integer. Non-positive values disable\ntracing.\n")
|
||||
docreflect.Register("main.showOptions.Pretty", "Pretty enables indented, human-readable output.\n")
|
||||
docreflect.Register("main.showOptions.Syntax", "Syntax specifies the filename of the syntax definition file.\n")
|
||||
docreflect.Register("main.showOptions.SyntaxString", "SyntaxString specifies the syntax as an inline string.\n")
|
||||
|
||||
@ -21,8 +21,9 @@ type formatOptions struct {
|
||||
// Syntax specifies the filename of the syntax definition file.
|
||||
Syntax []string
|
||||
|
||||
// MaxTraceLength enables tracing when set to a positive integer.
|
||||
MaxTraceLength int
|
||||
// MaxTraceLength configures tracing when set to a positive integer. Non-positive values disable
|
||||
// tracing.
|
||||
MaxTraceLength *int
|
||||
}
|
||||
|
||||
func formatSyntax(in io.Reader, out io.Writer, maxTraceLength int) error {
|
||||
@ -118,13 +119,18 @@ func format(o formatOptions, stdin io.Reader, stdout io.Writer, syntax ...string
|
||||
}
|
||||
}
|
||||
|
||||
mtl := defaultMaxTraceLength
|
||||
if o.MaxTraceLength != nil {
|
||||
mtl = *o.MaxTraceLength
|
||||
}
|
||||
|
||||
if len(files) > 0 {
|
||||
return formatFiles(files, o.InPlace, o.MaxTraceLength, stdout)
|
||||
return formatFiles(files, o.InPlace, mtl, stdout)
|
||||
}
|
||||
|
||||
if o.SyntaxString != nil {
|
||||
return formatInline(*o.SyntaxString, stdout, o.MaxTraceLength)
|
||||
return formatInline(*o.SyntaxString, stdout, mtl)
|
||||
}
|
||||
|
||||
return formatSyntax(stdin, stdout, o.MaxTraceLength)
|
||||
return formatSyntax(stdin, stdout, mtl)
|
||||
}
|
||||
|
||||
@ -21,8 +21,9 @@ type generateOptions struct {
|
||||
// Export determines whether the generated parse function is exported (visible outside its package).
|
||||
Export bool
|
||||
|
||||
// MaxTraceLength enables tracing when set to a positive integer.
|
||||
MaxTraceLength int
|
||||
// MaxTraceLength configures tracing when set to a positive integer. Non-positive values disable
|
||||
// tracing.
|
||||
MaxTraceLength *int
|
||||
}
|
||||
|
||||
// generate generates Go code that can parse arbitrary input with the provided syntax, and can be used embedded
|
||||
@ -37,7 +38,12 @@ func generate(o generateOptions, stdin io.Reader, stdout io.Writer, args ...stri
|
||||
}
|
||||
|
||||
defer finalizeSyntax()
|
||||
s := &treerack.Syntax{MaxTraceLength: o.MaxTraceLength}
|
||||
mtl := defaultMaxTraceLength
|
||||
if o.MaxTraceLength != nil {
|
||||
mtl = *o.MaxTraceLength
|
||||
}
|
||||
|
||||
s := &treerack.Syntax{MaxTraceLength: mtl}
|
||||
if err := s.ReadSyntax(syntax); err != nil {
|
||||
if terr := treerack.Trace(os.Stderr, err); err != nil {
|
||||
err = errors.Join(err, terr)
|
||||
|
||||
@ -32,7 +32,8 @@ argument), an inline string, or piped from standard input.
|
||||
|
||||
#### Options:
|
||||
|
||||
- --max-trace-length int: enables tracing when set to a positive integer.
|
||||
- --max-trace-length int: configures tracing when set to a positive integer. Non-positive values disable
|
||||
tracing.
|
||||
- --syntax string: specifies the filename of the syntax definition file.
|
||||
- --syntax-string string: specifies the syntax as an inline string.
|
||||
- --help: Show help.
|
||||
@ -58,7 +59,8 @@ positional argument filename, an inline string option, or piped from standard in
|
||||
|
||||
- --input string: specifies the filename of the input content to be validated.
|
||||
- --input-string string: specifies the input content as an inline string.
|
||||
- --max-trace-length int: enables tracing when set to a positive integer.
|
||||
- --max-trace-length int: configures tracing when set to a positive integer. Non-positive values disable
|
||||
tracing.
|
||||
- --syntax string: specifies the filename of the syntax definition file.
|
||||
- --syntax-string string: specifies the syntax as an inline string.
|
||||
- --help: Show help.
|
||||
@ -85,7 +87,8 @@ filename option, a positional argument filename, an inline string option, or pip
|
||||
- --indent string: specifies a custom indentation string for the output.
|
||||
- --input string: specifies the filename of the input content to be validated.
|
||||
- --input-string string: specifies the input content as an inline string.
|
||||
- --max-trace-length int: enables tracing when set to a positive integer.
|
||||
- --max-trace-length int: configures tracing when set to a positive integer. Non-positive values disable
|
||||
tracing.
|
||||
- --pretty bool: enables indented, human-readable output.
|
||||
- --syntax string: specifies the filename of the syntax definition file.
|
||||
- --syntax-string string: specifies the syntax as an inline string.
|
||||
@ -113,7 +116,8 @@ piped from standard input.
|
||||
#### Options:
|
||||
|
||||
- --export bool: determines whether the generated parse function is exported (visible outside its package).
|
||||
- --max-trace-length int: enables tracing when set to a positive integer.
|
||||
- --max-trace-length int: configures tracing when set to a positive integer. Non-positive values disable
|
||||
tracing.
|
||||
- --package-name string: specifies the package name for the generated code. Defaults to main.
|
||||
- --syntax string: specifies the filename of the syntax definition file.
|
||||
- --syntax-string string: specifies the syntax as an inline string.
|
||||
@ -137,7 +141,8 @@ when formatting files in place, or print the formatted syntax to stdout.
|
||||
|
||||
- --in-place bool: specifies if an input file should be formatted in-place instead of printing the formatted
|
||||
results to the standard output.
|
||||
- --max-trace-length int: enables tracing when set to a positive integer.
|
||||
- --max-trace-length int: configures tracing when set to a positive integer. Non-positive values disable
|
||||
tracing.
|
||||
- --syntax string \[\*\]: specifies the filename of the syntax definition file.
|
||||
- --syntax-string string: specifies the syntax as an inline string.
|
||||
- --help: Show help.
|
||||
|
||||
@ -28,8 +28,9 @@ type showOptions struct {
|
||||
// Indent specifies a custom indentation string for the output.
|
||||
Indent string
|
||||
|
||||
// MaxTraceLength enables tracing when set to a positive integer.
|
||||
MaxTraceLength int
|
||||
// MaxTraceLength configures tracing when set to a positive integer. Non-positive values disable
|
||||
// tracing.
|
||||
MaxTraceLength *int
|
||||
}
|
||||
|
||||
type node struct {
|
||||
@ -75,7 +76,12 @@ func show(o showOptions, stdin io.Reader, stdout io.Writer, args ...string) erro
|
||||
}
|
||||
|
||||
defer finalizeInput()
|
||||
s := &treerack.Syntax{MaxTraceLength: o.MaxTraceLength}
|
||||
mtl := defaultMaxTraceLength
|
||||
if o.MaxTraceLength != nil {
|
||||
mtl = *o.MaxTraceLength
|
||||
}
|
||||
|
||||
s := &treerack.Syntax{MaxTraceLength: mtl}
|
||||
if err := s.ReadSyntax(syntax); err != nil {
|
||||
if terr := treerack.Trace(os.Stderr, err); err != nil {
|
||||
err = errors.Join(err, terr)
|
||||
|
||||
Loading…
Reference in New Issue
Block a user