diff --git a/birdie_snapshots/cmd1_help.accepted b/birdie_snapshots/cmd1_help.accepted new file mode 100644 index 0000000..5787211 --- /dev/null +++ b/birdie_snapshots/cmd1_help.accepted @@ -0,0 +1,24 @@ +--- +version: 1.1.5 +title: cmd1 help +file: ./test/glint_test.gleam +test_name: help_test +--- +Some awesome global help text! + +Command: cmd1 + +This is cmd1 + +USAGE: + gleam run -m test cmd1 ( cmd3 | cmd4 ) [ ARGS ] [ --flag2= --flag5= --global= ] + +FLAGS: + --flag2= This is flag2 + --flag5= This is flag5 + --global= This is a global flag + --help Print help information + +SUBCOMMANDS: + cmd3 This is cmd3 + cmd4 This is cmd4 \ No newline at end of file diff --git a/birdie_snapshots/cmd2_help.accepted b/birdie_snapshots/cmd2_help.accepted new file mode 100644 index 0000000..57216ba --- /dev/null +++ b/birdie_snapshots/cmd2_help.accepted @@ -0,0 +1,18 @@ +--- +version: 1.1.5 +title: cmd2 help +file: ./test/glint_test.gleam +test_name: help_test +--- +Some awesome global help text! + +Command: cmd2 + +This is cmd2 + +USAGE: + gleam run -m test cmd2 [ --global= ] + +FLAGS: + --global= This is a global flag + --help Print help information \ No newline at end of file diff --git a/birdie_snapshots/cmd3_help.accepted b/birdie_snapshots/cmd3_help.accepted new file mode 100644 index 0000000..7695b29 --- /dev/null +++ b/birdie_snapshots/cmd3_help.accepted @@ -0,0 +1,19 @@ +--- +version: 1.1.5 +title: cmd3 help +file: ./test/glint_test.gleam +test_name: help_test +--- +Some awesome global help text! + +Command: cmd1 cmd3 + +This is cmd3 + +USAGE: + gleam run -m test cmd1 cmd3 [ 2 or more arguments ] [ --flag3= --global= ] + +FLAGS: + --flag3= This is flag3 + --global= This is a global flag + --help Print help information \ No newline at end of file diff --git a/birdie_snapshots/cmd4_help.accepted b/birdie_snapshots/cmd4_help.accepted new file mode 100644 index 0000000..51f32ba --- /dev/null +++ b/birdie_snapshots/cmd4_help.accepted @@ -0,0 +1,19 @@ +--- +version: 1.1.5 +title: cmd4 help +file: ./test/glint_test.gleam +test_name: help_test +--- +Some awesome global help text! + +Command: cmd1 cmd4 + +This is cmd4 + +USAGE: + gleam run -m test cmd1 cmd4 [ --flag4= --global= ] + +FLAGS: + --flag4= This is flag4 + --global= This is a global flag + --help Print help information \ No newline at end of file diff --git a/birdie_snapshots/cmd6_help.accepted b/birdie_snapshots/cmd6_help.accepted new file mode 100644 index 0000000..ce82e80 --- /dev/null +++ b/birdie_snapshots/cmd6_help.accepted @@ -0,0 +1,21 @@ +--- +version: 1.1.5 +title: cmd6 help +file: ./test/glint_test.gleam +test_name: help_test +--- +Some awesome global help text! + +Command: cmd5 cmd6 + +This is cmd6 + +USAGE: + gleam run -m test cmd5 cmd6 ( cmd7 ) [ ARGS ] [ --global= ] + +FLAGS: + --global= This is a global flag + --help Print help information + +SUBCOMMANDS: + cmd7 This is cmd7 \ No newline at end of file diff --git a/birdie_snapshots/cmd7_help.accepted b/birdie_snapshots/cmd7_help.accepted new file mode 100644 index 0000000..4f913ce --- /dev/null +++ b/birdie_snapshots/cmd7_help.accepted @@ -0,0 +1,14 @@ +--- +version: 1.1.5 +title: cmd7 help +file: ./test/glint_test.gleam +test_name: help_test +--- +Some awesome global help text! + +Command: cmd5 cmd6 cmd7 + +This is cmd7 + +USAGE: + gleam run -m test cmd5 cmd6 cmd7 [ ARGS ] \ No newline at end of file diff --git a/birdie_snapshots/root_help.accepted b/birdie_snapshots/root_help.accepted new file mode 100644 index 0000000..2279070 --- /dev/null +++ b/birdie_snapshots/root_help.accepted @@ -0,0 +1,22 @@ +--- +version: 1.1.5 +title: root help +file: ./test/glint_test.gleam +test_name: help_test +--- +Some awesome global help text! + +This is the root command + +USAGE: + gleam run -m test ( cmd1 | cmd2 | cmd5 ) [ ARGS ] [ --flag1= --global= ] + +FLAGS: + --flag1= This is flag1 + --global= This is a global flag + --help Print help information + +SUBCOMMANDS: + cmd1 This is cmd1 + cmd2 This is cmd2 + cmd5 \ No newline at end of file diff --git a/gleam.toml b/gleam.toml index da56888..1979d9c 100644 --- a/gleam.toml +++ b/gleam.toml @@ -22,3 +22,4 @@ gleam_community_colour = "~> 1.0" [dev-dependencies] gleeunit = "~> 1.0" argv = ">= 1.0.2 and < 2.0.0" +birdie = ">= 1.1.5 and < 2.0.0" diff --git a/manifest.toml b/manifest.toml index 5bc82ae..da6f346 100644 --- a/manifest.toml +++ b/manifest.toml @@ -3,17 +3,27 @@ packages = [ { name = "argv", version = "1.0.2", build_tools = ["gleam"], requirements = [], otp_app = "argv", source = "hex", outer_checksum = "BA1FF0929525DEBA1CE67256E5ADF77A7CDDFE729E3E3F57A5BDCAA031DED09D" }, + { name = "birdie", version = "1.1.5", build_tools = ["gleam"], requirements = ["argv", "filepath", "glance", "gleam_community_ansi", "gleam_erlang", "gleam_stdlib", "justin", "rank", "simplifile", "trie_again"], otp_app = "birdie", source = "hex", outer_checksum = "E1B6CB7B9EDE8F4C67F7E68C9FB45FBAA54881545F85D315D2B179560CC63F60" }, + { name = "filepath", version = "1.0.0", build_tools = ["gleam"], requirements = ["gleam_stdlib"], otp_app = "filepath", source = "hex", outer_checksum = "EFB6FF65C98B2A16378ABC3EE2B14124168C0CE5201553DE652E2644DCFDB594" }, + { name = "glance", version = "0.11.0", build_tools = ["gleam"], requirements = ["gleam_stdlib", "glexer"], otp_app = "glance", source = "hex", outer_checksum = "8F3314D27773B7C3B9FB58D8C02C634290422CE531988C0394FA0DF8676B964D" }, { name = "gleam_community_ansi", version = "1.4.0", build_tools = ["gleam"], requirements = ["gleam_community_colour", "gleam_stdlib"], otp_app = "gleam_community_ansi", source = "hex", outer_checksum = "FE79E08BF97009729259B6357EC058315B6FBB916FAD1C2FF9355115FEB0D3A4" }, { name = "gleam_community_colour", version = "1.4.0", build_tools = ["gleam"], requirements = ["gleam_json", "gleam_stdlib"], otp_app = "gleam_community_colour", source = "hex", outer_checksum = "795964217EBEDB3DA656F5EB8F67D7AD22872EB95182042D3E7AFEF32D3FD2FE" }, + { name = "gleam_erlang", version = "0.25.0", build_tools = ["gleam"], requirements = ["gleam_stdlib"], otp_app = "gleam_erlang", source = "hex", outer_checksum = "054D571A7092D2A9727B3E5D183B7507DAB0DA41556EC9133606F09C15497373" }, { name = "gleam_json", version = "1.0.1", build_tools = ["gleam"], requirements = ["gleam_stdlib", "thoas"], otp_app = "gleam_json", source = "hex", outer_checksum = "9063D14D25406326C0255BDA0021541E797D8A7A12573D849462CAFED459F6EB" }, { name = "gleam_stdlib", version = "0.37.0", build_tools = ["gleam"], requirements = [], otp_app = "gleam_stdlib", source = "hex", outer_checksum = "5398BD6C2ABA17338F676F42F404B9B7BABE1C8DC7380031ACB05BBE1BCF3742" }, { name = "gleeunit", version = "1.1.2", build_tools = ["gleam"], requirements = ["gleam_stdlib"], otp_app = "gleeunit", source = "hex", outer_checksum = "72CDC3D3F719478F26C4E2C5FED3E657AC81EC14A47D2D2DEBB8693CA3220C3B" }, + { name = "glexer", version = "1.0.1", build_tools = ["gleam"], requirements = ["gleam_stdlib"], otp_app = "glexer", source = "hex", outer_checksum = "BD477AD657C2B637FEF75F2405FAEFFA533F277A74EF1A5E17B55B1178C228FB" }, + { name = "justin", version = "1.0.1", build_tools = ["gleam"], requirements = ["gleam_stdlib"], otp_app = "justin", source = "hex", outer_checksum = "7FA0C6DB78640C6DC5FBFD59BF3456009F3F8B485BF6825E97E1EB44E9A1E2CD" }, + { name = "rank", version = "1.0.0", build_tools = ["gleam"], requirements = ["gleam_stdlib"], otp_app = "rank", source = "hex", outer_checksum = "5660E361F0E49CBB714CC57CC4C89C63415D8986F05B2DA0C719D5642FAD91C9" }, + { name = "simplifile", version = "1.7.0", build_tools = ["gleam"], requirements = ["filepath", "gleam_stdlib"], otp_app = "simplifile", source = "hex", outer_checksum = "1D5DFA3A2F9319EC85825F6ED88B8E449F381B0D55A62F5E61424E748E7DDEB0" }, { name = "snag", version = "0.3.0", build_tools = ["gleam"], requirements = ["gleam_stdlib"], otp_app = "snag", source = "hex", outer_checksum = "54D32E16E33655346AA3E66CBA7E191DE0A8793D2C05284E3EFB90AD2CE92BCC" }, { name = "thoas", version = "1.2.0", build_tools = ["rebar3"], requirements = [], otp_app = "thoas", source = "hex", outer_checksum = "540C8CB7D9257F2AD0A14145DC23560F91ACDCA995F0CCBA779EB33AF5D859D1" }, + { name = "trie_again", version = "1.1.2", build_tools = ["gleam"], requirements = ["gleam_stdlib"], otp_app = "trie_again", source = "hex", outer_checksum = "5B19176F52B1BD98831B57FDC97BD1F88C8A403D6D8C63471407E78598E27184" }, ] [requirements] argv = { version = ">= 1.0.2 and < 2.0.0" } +birdie = { version = ">= 1.1.5 and < 2.0.0"} gleam_community_ansi = { version = "~> 1.0" } gleam_community_colour = { version = "~> 1.0" } gleam_stdlib = { version = "~> 0.36 or ~> 1.0" } diff --git a/test/glint_test.gleam b/test/glint_test.gleam index 3b8adb6..67fcab3 100644 --- a/test/glint_test.gleam +++ b/test/glint_test.gleam @@ -1,3 +1,5 @@ +import birdie +import gleam/result import gleeunit import gleeunit/should import glint.{Help, Out} @@ -192,149 +194,46 @@ pub fn help_test() { glint.execute(cli, ["cmd2", "1", "2", "3"]) |> should.be_error() + let assert_unwrap_help = fn(res: Result(glint.Out(a), String)) -> String { + let assert Ok(Help(help)) = res + help + } + // help message for root command glint.execute(cli, ["--help"]) - |> should.equal( - Ok(Help( - "Some awesome global help text! - -This is the root command - -USAGE: -\tgleam run -m test ( cmd1 | cmd2 | cmd5 ) [ ARGS ] [ --flag1= --global= ] - -FLAGS: -\t--flag1=\t\tThis is flag1 -\t--global=\t\tThis is a global flag -\t--help\t\t\tPrint help information - -SUBCOMMANDS: -\tcmd1\t\tThis is cmd1 -\tcmd2\t\tThis is cmd2 -\tcmd5", - )), - ) + |> assert_unwrap_help + |> birdie.snap("root help") // help message for command glint.execute(cli, ["cmd1", "--help"]) - |> should.equal( - Ok(Help( - "Some awesome global help text! - -Command: cmd1 - -This is cmd1 - -USAGE: -\tgleam run -m test cmd1 ( cmd3 | cmd4 ) [ ARGS ] [ --flag2= --flag5= --global= ] - -FLAGS: -\t--flag2=\t\tThis is flag2 -\t--flag5=\t\tThis is flag5 -\t--global=\t\tThis is a global flag -\t--help\t\t\tPrint help information - -SUBCOMMANDS: -\tcmd3\t\tThis is cmd3 -\tcmd4\t\tThis is cmd4", - )), - ) + |> assert_unwrap_help + |> birdie.snap("cmd1 help") // help message for nested command glint.execute(cli, ["cmd1", "cmd4", "--help"]) - |> should.equal( - Ok(Help( - "Some awesome global help text! - -Command: cmd1 cmd4 - -This is cmd4 + |> assert_unwrap_help + |> birdie.snap("cmd4 help") -USAGE: -\tgleam run -m test cmd1 cmd4 [ --flag4= --global= ] - -FLAGS: -\t--flag4=\t\tThis is flag4 -\t--global=\t\tThis is a global flag -\t--help\t\t\tPrint help information", - )), - ) // help message for command with no additional flags glint.execute(cli, ["cmd2", "--help"]) - |> should.equal( - Ok(Help( - "Some awesome global help text! - -Command: cmd2 - -This is cmd2 - -USAGE: -\tgleam run -m test cmd2 [ --global= ] - -FLAGS: -\t--global=\t\tThis is a global flag -\t--help\t\t\tPrint help information", - )), - ) + |> assert_unwrap_help + |> birdie.snap("cmd2 help") // help message for command with no additional flags glint.execute(cli, ["cmd1", "cmd3", "--help"]) - |> should.equal( - Ok(Help( - "Some awesome global help text! - -Command: cmd1 cmd3 - -This is cmd3 - -USAGE: -\tgleam run -m test cmd1 cmd3 [ 2 or more arguments ] [ --flag3= --global= ] - -FLAGS: -\t--flag3=\t\tThis is flag3 -\t--global=\t\tThis is a global flag -\t--help\t\t\tPrint help information", - )), - ) + |> assert_unwrap_help + |> birdie.snap("cmd3 help") // help message for command a subcommand whose help was set with glint.path_help glint.execute(cli, ["cmd5", "cmd6", "--help"]) - |> should.equal( - Ok(Help( - "Some awesome global help text! - -Command: cmd5 cmd6 - -This is cmd6 - -USAGE: -\tgleam run -m test cmd5 cmd6 ( cmd7 ) [ ARGS ] [ --global= ] - -FLAGS: -\t--global=\t\tThis is a global flag -\t--help\t\t\tPrint help information - -SUBCOMMANDS: -\tcmd7\t\tThis is cmd7", - )), - ) + |> assert_unwrap_help + |> birdie.snap("cmd6 help") // help message for command that had help_text set with glint.glint.path_help // has no children or command runner set so no other details are available glint.execute(cli, ["cmd5", "cmd6", "cmd7", "--help"]) - |> should.equal( - Ok(Help( - "Some awesome global help text! - -Command: cmd5 cmd6 cmd7 - -This is cmd7 - -USAGE: -\tgleam run -m test cmd5 cmd6 cmd7 [ ARGS ]", - )), - ) + |> assert_unwrap_help + |> birdie.snap("cmd7 help") } pub fn global_and_group_flags_test() {