From f0356645e6663955dff221d21355f09e8d46cf29 Mon Sep 17 00:00:00 2001 From: Harrison Howard Date: Fri, 17 May 2024 21:44:53 +1000 Subject: [PATCH] #16 Clean up the command utils --- src/commands/auth.gleam | 6 ++++-- src/commands/config.gleam | 6 ++++-- src/commands/help.gleam | 27 +++++++++++++++++++++--- src/commands/watch.gleam | 6 ++++-- src/util/commands/auth_tool.gleam | 2 -- src/util/commands/config_tool.gleam | 2 -- src/util/commands/help_tool.gleam | 32 ----------------------------- src/util/commands/watch_tool.gleam | 2 -- 8 files changed, 36 insertions(+), 47 deletions(-) delete mode 100644 src/util/commands/auth_tool.gleam delete mode 100644 src/util/commands/config_tool.gleam delete mode 100644 src/util/commands/help_tool.gleam delete mode 100644 src/util/commands/watch_tool.gleam diff --git a/src/commands/auth.gleam b/src/commands/auth.gleam index 4de7e4a..32fc3d2 100644 --- a/src/commands/auth.gleam +++ b/src/commands/auth.gleam @@ -8,10 +8,12 @@ import plex_pin_auth import plex_pin_auth/util/parser.{type PlexError, type PlexPin} import repeatedly import util/client_identifier -import util/commands/auth_tool import util/env.{ConfigOption} import util/terminal +/// Description for the 'auth' command +pub const description = "Setups the Plex authentication config." + /// The interval in which we poll the server for the token const interval_ms = 2000 @@ -110,7 +112,7 @@ pub fn command(to glint: Glint(Nil)) { to: glint, at: ["auth"], do: glint.command(do) - |> glint.description(auth_tool.description), + |> glint.description(description), ) } diff --git a/src/commands/config.gleam b/src/commands/config.gleam index 16df75b..b16f889 100644 --- a/src/commands/config.gleam +++ b/src/commands/config.gleam @@ -6,10 +6,12 @@ import gleam/io import gleam/option.{None, Some} import gleam/string import glint.{type CommandInput, type Glint} -import util/commands/watch_tool import util/env.{ConfigOption} import util/terminal +/// Description for the 'config' command +pub const description = "Write the config file for the your specific environment." + /// The 'config' command logic fn do(_input: CommandInput) { // Basic information for user to understand what's going on @@ -121,6 +123,6 @@ pub fn command(to glint: Glint(Nil)) { to: glint, at: ["config"], do: glint.command(do) - |> glint.description(watch_tool.description), + |> glint.description(description), ) } diff --git a/src/commands/help.gleam b/src/commands/help.gleam index 1acd8c8..ec10f67 100644 --- a/src/commands/help.gleam +++ b/src/commands/help.gleam @@ -1,11 +1,32 @@ //// Command logic for the help command. This is the base help command when entering an unknown command. +import commands/auth.{description as auth_description} +import commands/config.{description as config_description} +import commands/watch.{description as watch_description} +import gleam/io import glint.{type CommandInput, type Glint} -import util/commands/help_tool + +/// Description for the 'help' command +const description = "Below are the commands that are available in this project.\nIf you need help with a specific command attach the flag '--help' when running the command." /// Runs the print function for the 'help' command fn do(_input: CommandInput) { - help_tool.print() + io.println( + description + <> "\n\n" + <> "USAGE:\n" + <> "\tplexrpc [ ARGS ]" + <> "\n\n" + <> "SUBCOMMANDS:\n" + <> "\twatch\t\t" + <> watch_description + <> "\n" + <> "\tauth\t\t" + <> auth_description + <> "\n" + <> "\tconfig\t\t" + <> config_description, + ) } /// Adds the 'help' command to the glint instance. @@ -14,6 +35,6 @@ pub fn command(to glint: Glint(Nil)) { to: glint, at: [], do: glint.command(do) - |> glint.description(help_tool.description), + |> glint.description(description), ) } diff --git a/src/commands/watch.gleam b/src/commands/watch.gleam index f6d9b6c..1013e1e 100644 --- a/src/commands/watch.gleam +++ b/src/commands/watch.gleam @@ -2,7 +2,9 @@ import gleam/io import glint.{type CommandInput, type Glint} -import util/commands/watch_tool + +/// Description for the 'watch' command +pub const description = "Initiate the Plex RPC. Requires Plex auth and Discord to be open." /// The 'watch' command logic fn do(_input: CommandInput) { @@ -15,6 +17,6 @@ pub fn command(to glint: Glint(Nil)) { to: glint, at: ["watch"], do: glint.command(do) - |> glint.description(watch_tool.description), + |> glint.description(description), ) } diff --git a/src/util/commands/auth_tool.gleam b/src/util/commands/auth_tool.gleam deleted file mode 100644 index 1862bea..0000000 --- a/src/util/commands/auth_tool.gleam +++ /dev/null @@ -1,2 +0,0 @@ -/// Description for the 'auth' command -pub const description = "Setups the Plex authentication config." diff --git a/src/util/commands/config_tool.gleam b/src/util/commands/config_tool.gleam deleted file mode 100644 index 7d3dfc5..0000000 --- a/src/util/commands/config_tool.gleam +++ /dev/null @@ -1,2 +0,0 @@ -/// Description for the 'config' command -pub const description = "Write the config file for the your specific environment." diff --git a/src/util/commands/help_tool.gleam b/src/util/commands/help_tool.gleam deleted file mode 100644 index 29e8d98..0000000 --- a/src/util/commands/help_tool.gleam +++ /dev/null @@ -1,32 +0,0 @@ -//// The utility file for the help command and flag - -import gleam/io - -// Command utils -import util/commands/auth_tool -import util/commands/config_tool -import util/commands/watch_tool - -/// Description for the 'help' command -pub const description = "Below are the commands that are available in this project.\nIf you need help with a specific command attach the flag '--help' when running the command." - -/// The output print for the base 'help' command.\ -/// Does not represent the 'help' flag output -pub fn print() { - io.println( - description - <> "\n\n" - <> "USAGE:\n" - <> "\tplexrpc [ ARGS ]" - <> "\n\n" - <> "SUBCOMMANDS:\n" - <> "\twatch\t\t" - <> watch_tool.description - <> "\n" - <> "\tauth\t\t" - <> auth_tool.description - <> "\n" - <> "\tconfig\t\t" - <> config_tool.description, - ) -} diff --git a/src/util/commands/watch_tool.gleam b/src/util/commands/watch_tool.gleam deleted file mode 100644 index 4dafcc1..0000000 --- a/src/util/commands/watch_tool.gleam +++ /dev/null @@ -1,2 +0,0 @@ -/// Description for the 'watch' command -pub const description = "Initiate the Plex RPC. Requires Plex auth and Discord to be open."