From 7b4dc88d8ba450c1e274136a90fa489244630d95 Mon Sep 17 00:00:00 2001 From: andrey Date: Tue, 6 Jan 2026 16:45:39 +0300 Subject: [PATCH 1/2] update example --- example/cmd/config/main.go | 4 +++- example/cmd/console/main.go | 2 ++ example/go.mod | 4 ++-- example/go.sum | 10 ++++------ example/pkg/command/create_user.go | 8 ++++---- 5 files changed, 15 insertions(+), 13 deletions(-) diff --git a/example/cmd/config/main.go b/example/cmd/config/main.go index 22732a7..25cb8e6 100644 --- a/example/cmd/config/main.go +++ b/example/cmd/config/main.go @@ -9,6 +9,7 @@ import ( "gitoa.ru/go-4devs/config/provider/env" "gitoa.ru/go-4devs/config/provider/memory" "gitoa.ru/go-4devs/console" + "gitoa.ru/go-4devs/console/command/dump" "gitoa.ru/go-4devs/console/example/pkg/command" ) @@ -23,12 +24,13 @@ func main() { console. New(console.WithInput( chain.New( - arg.New(arg.WithArgs(os.Args)), + arg.New(arg.WithArgs(os.Args[console.ResolveSkip(0):])), env.New(Namespace, AppName), &memory.Default{}, ), )). Add( + dump.Command(), command.Long(), command.Args(), ). diff --git a/example/cmd/console/main.go b/example/cmd/console/main.go index b41e179..6b89acf 100644 --- a/example/cmd/console/main.go +++ b/example/cmd/console/main.go @@ -4,6 +4,7 @@ import ( "context" "gitoa.ru/go-4devs/console" + "gitoa.ru/go-4devs/console/command/dump" "gitoa.ru/go-4devs/console/example/pkg/command" ) @@ -11,6 +12,7 @@ func main() { console. New(). Add( + dump.Command(), command.Hello(), command.Args(), command.Hidden(), diff --git a/example/go.mod b/example/go.mod index f55aeee..f850c97 100644 --- a/example/go.mod +++ b/example/go.mod @@ -5,6 +5,6 @@ go 1.24.0 toolchain go1.24.1 require ( - gitoa.ru/go-4devs/config v0.0.8 - gitoa.ru/go-4devs/console v0.2.1-0.20260105202444-e2c6fc0a35a4 + gitoa.ru/go-4devs/config v0.0.10 + gitoa.ru/go-4devs/console v0.4.0 ) diff --git a/example/go.sum b/example/go.sum index 2cf2b51..065c9a0 100644 --- a/example/go.sum +++ b/example/go.sum @@ -1,6 +1,4 @@ -gitoa.ru/go-4devs/config v0.0.8 h1:o4p8I9jWJMfiFVVKr50IqCGj1fF+8kmSPDkH0deRvn4= -gitoa.ru/go-4devs/config v0.0.8/go.mod h1:jHKqVafFVW400LC0M4i1ifPapiI9sqpX/QTh+VMadKw= -gitoa.ru/go-4devs/console v0.2.0 h1:6lsbArs99GA8vGdnwNDThZNKjFNctNtTlSCUjhgwIpU= -gitoa.ru/go-4devs/console v0.2.0/go.mod h1:xi4Svw7T+lylckAQiJQS/2qwDwF4YbIanlhcbQrBAiI= -gitoa.ru/go-4devs/console v0.2.1-0.20260105202444-e2c6fc0a35a4 h1:zOk/59IvgUfCDL6ub6WX4hsqDK79FsZR0gf7s7t3fXM= -gitoa.ru/go-4devs/console v0.2.1-0.20260105202444-e2c6fc0a35a4/go.mod h1:PG/Zyj1dLh7eFlj9bgnV58+Ys6I/MTrS0q9W7oD7z4U= +gitoa.ru/go-4devs/config v0.0.10 h1:NSagD0voj77/IGqRGsbR0DZmDvFcxbx+oRoWQnLnSy4= +gitoa.ru/go-4devs/config v0.0.10/go.mod h1:cLW1+4E4uM4Pw+z4RuKEKbO1Lz6UTs2b2fTPyeEgTx8= +gitoa.ru/go-4devs/console v0.4.0 h1:3N4VMWsHsaP32nWHxALxjPhp/MhYx1hXZdDl3xGJQ3k= +gitoa.ru/go-4devs/console v0.4.0/go.mod h1:+J69iA4KQfC2H1FxItwL4pLkb3oW8g466qUSo0jWYjo= diff --git a/example/pkg/command/create_user.go b/example/pkg/command/create_user.go index e3205f3..241237e 100644 --- a/example/pkg/command/create_user.go +++ b/example/pkg/command/create_user.go @@ -5,12 +5,12 @@ import ( "gitoa.ru/go-4devs/config" "gitoa.ru/go-4devs/config/definition/option" - cparam "gitoa.ru/go-4devs/config/param" + "gitoa.ru/go-4devs/config/param" argument "gitoa.ru/go-4devs/config/provider/arg" "gitoa.ru/go-4devs/console" "gitoa.ru/go-4devs/console/command" "gitoa.ru/go-4devs/console/output" - "gitoa.ru/go-4devs/console/param" + "gitoa.ru/go-4devs/console/setting" ) func CreateUser(required bool) command.Command { @@ -19,7 +19,7 @@ func CreateUser(required bool) command.Command { "Creates a new user.", UserExecute, command.Configure(UserConfigure(required)), - command.Help(func(param.HData) (string, error) { + command.Help(func(setting.HData) (string, error) { return "This command allows you to create a user...", nil }), ) @@ -27,7 +27,7 @@ func CreateUser(required bool) command.Command { func UserConfigure(required bool) func(_ context.Context, cfg config.Definition) error { return func(_ context.Context, cfg config.Definition) error { - var opts []cparam.Option + var opts []param.Option if required { opts = append(opts, option.Required) } From 85edd5acecd6d058f6a0fa7a190b568d3cb7c692 Mon Sep 17 00:00:00 2001 From: andrey Date: Tue, 6 Jan 2026 16:45:56 +0300 Subject: [PATCH 2/2] update help for list and help command --- command/help/command.go | 3 +-- command/list/help.go | 6 ++---- output/descriptor/txt.go | 14 +++++--------- 3 files changed, 8 insertions(+), 15 deletions(-) diff --git a/command/help/command.go b/command/help/command.go index 0f192e0..e45899e 100644 --- a/command/help/command.go +++ b/command/help/command.go @@ -126,8 +126,7 @@ func Execute(ctx context.Context, in config.Provider, out output.Output) error { return nil } -const tpl = ` -The %[2]s command displays help for a given command: +const tpl = `The %[2]s command displays help for a given command: %[1]s %[2]s list You can also output the help in other formats by using the --format option: %[1]s %[2]s --format=xml list diff --git a/command/list/help.go b/command/list/help.go index 5c5393f..63213fd 100644 --- a/command/list/help.go +++ b/command/list/help.go @@ -6,14 +6,12 @@ import ( "gitoa.ru/go-4devs/console/setting" ) -const tpl = ` -The %[2]s command lists all commands: +const tpl = `The %[2]s command lists all commands: %[1]s %[2]s You can also display the commands for a specific namespace: %[1]s %[2]s test You can also output the information in other formats by using the --format option: - %[1]s %[2]s --format=xml -` + %[1]s %[2]s --format=xml` func Help(data setting.HData) (string, error) { return fmt.Sprintf(tpl, data.Bin, data.Name), nil diff --git a/output/descriptor/txt.go b/output/descriptor/txt.go index 2fef9f5..9ac6c00 100644 --- a/output/descriptor/txt.go +++ b/output/descriptor/txt.go @@ -29,7 +29,8 @@ var ( "commands": txtCommands, } - txtHelpTemplate = template.Must(template.New("txt_template"). + txtHelpTemplate = template.Must( + template.New("txt_template"). Funcs(txtFunc). Parse(` {{- if .Description -}} @@ -38,8 +39,8 @@ var ( {{ end -}} {{- usage . }} {{- definition .Options }} -{{- help . }} - `)) +{{- help . }}`), + ) txtListTemplate = template.Must(template.New("txt_list"). Funcs(txtFunc). @@ -149,12 +150,7 @@ func txtHelp(cmd Command) string { return "" } - var buf bytes.Buffer - - buf.WriteString("\nHelp:") - buf.WriteString(cmd.Help) - - return buf.String() + return "\nHelp:\n" + cmd.Help + "\n" } func txtDefinition(options config.Options) string {