From aba563ab9a885e5233fa8b9e019d79ab9d209ace Mon Sep 17 00:00:00 2001 From: Arpad Ryszka Date: Sat, 6 Jun 2026 22:06:11 +0200 Subject: [PATCH] set tracing on by default for the utility commands --- cmd/treerack/check.go | 12 +++++++++--- cmd/treerack/checksyntax.go | 14 +++++++++++--- cmd/treerack/docreflect.gen.go | 11 ++++++----- cmd/treerack/format.go | 16 +++++++++++----- cmd/treerack/generate.go | 12 +++++++++--- cmd/treerack/readme.md | 15 ++++++++++----- cmd/treerack/show.go | 12 +++++++++--- 7 files changed, 65 insertions(+), 27 deletions(-) diff --git a/cmd/treerack/check.go b/cmd/treerack/check.go index bd9bfcc..1da0029 100644 --- a/cmd/treerack/check.go +++ b/cmd/treerack/check.go @@ -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) diff --git a/cmd/treerack/checksyntax.go b/cmd/treerack/checksyntax.go index a121659..9145b9b 100644 --- a/cmd/treerack/checksyntax.go +++ b/cmd/treerack/checksyntax.go @@ -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) diff --git a/cmd/treerack/docreflect.gen.go b/cmd/treerack/docreflect.gen.go index ce8ae1b..334a9a5 100644 --- a/cmd/treerack/docreflect.gen.go +++ b/cmd/treerack/docreflect.gen.go @@ -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") diff --git a/cmd/treerack/format.go b/cmd/treerack/format.go index bf924d7..fa36ff6 100644 --- a/cmd/treerack/format.go +++ b/cmd/treerack/format.go @@ -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) } diff --git a/cmd/treerack/generate.go b/cmd/treerack/generate.go index 2eb94c0..061fa3a 100644 --- a/cmd/treerack/generate.go +++ b/cmd/treerack/generate.go @@ -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) diff --git a/cmd/treerack/readme.md b/cmd/treerack/readme.md index b84f8fe..453133b 100644 --- a/cmd/treerack/readme.md +++ b/cmd/treerack/readme.md @@ -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. diff --git a/cmd/treerack/show.go b/cmd/treerack/show.go index 8b84b6f..6aa2d7a 100644 --- a/cmd/treerack/show.go +++ b/cmd/treerack/show.go @@ -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)