dropshell release 2025.0521.1906
Some checks failed
Dropshell Test / Build_and_Test (push) Has been cancelled
Some checks failed
Dropshell Test / Build_and_Test (push) Has been cancelled
This commit is contained in:
parent
1b16741288
commit
7a710b525f
@ -2,6 +2,7 @@ cmake_minimum_required(VERSION 3.10)
|
|||||||
project(dropshell VERSION 1.0.0 LANGUAGES CXX)
|
project(dropshell VERSION 1.0.0 LANGUAGES CXX)
|
||||||
|
|
||||||
set(CMAKE_CXX_STANDARD 23)
|
set(CMAKE_CXX_STANDARD 23)
|
||||||
|
set(CMAKE_C_STANDARD 23)
|
||||||
set(CMAKE_CXX_STANDARD_REQUIRED ON)
|
set(CMAKE_CXX_STANDARD_REQUIRED ON)
|
||||||
|
|
||||||
# Set default build type to Release if not specified
|
# Set default build type to Release if not specified
|
||||||
|
@ -94,7 +94,7 @@ namespace dropshell
|
|||||||
std::string line;
|
std::string line;
|
||||||
while (std::getline(readme_file, line))
|
while (std::getline(readme_file, line))
|
||||||
{
|
{
|
||||||
info << substitute_provided_key_value_pairs(line, all_env_vars) << std::endl;
|
rawout << substitute_provided_key_value_pairs(line, all_env_vars) << std::endl;
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
@ -55,6 +55,11 @@ void help_autocomplete(const CommandContext& ctx) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void show_command(const std::string& cmd) {
|
void show_command(const std::string& cmd) {
|
||||||
|
// get console width
|
||||||
|
int width = get_console_width() - 6; // 5 for [INF] + 1 for space
|
||||||
|
int firstcol = 34;
|
||||||
|
int secondcol = width - firstcol - 3;
|
||||||
|
|
||||||
const auto& cmd_info = CommandRegistry::instance().find_command(cmd);
|
const auto& cmd_info = CommandRegistry::instance().find_command(cmd);
|
||||||
if (!cmd_info)
|
if (!cmd_info)
|
||||||
{
|
{
|
||||||
@ -62,9 +67,22 @@ void show_command(const std::string& cmd) {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
info << " ";
|
if (cmd_info->help_usage.length() < width-secondcol)
|
||||||
info << left_align(cmd_info->help_usage, 32);
|
{
|
||||||
info << cmd_info->help_description << std::endl;
|
std::string remaining_description = cmd_info->help_description;
|
||||||
|
|
||||||
|
info << " " << left_align(cmd_info->help_usage, firstcol) << get_line_wrap(remaining_description, secondcol);
|
||||||
|
while (!remaining_description.empty())
|
||||||
|
info << " " << left_align(" ",firstcol) << get_line_wrap(remaining_description, secondcol-1);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
info << " " << cmd_info->help_usage << std::endl;
|
||||||
|
std::string remaining_description = cmd_info->help_description;
|
||||||
|
info << " " << left_align(" ",firstcol) << get_line_wrap(remaining_description, secondcol);
|
||||||
|
while (!remaining_description.empty())
|
||||||
|
info << " " << left_align(" ",firstcol) << get_line_wrap(remaining_description, secondcol-1);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
extern const std::string VERSION;
|
extern const std::string VERSION;
|
||||||
@ -106,7 +124,7 @@ int help_handler(const CommandContext& ctx) {
|
|||||||
if (ctx.args.size() > 0)
|
if (ctx.args.size() > 0)
|
||||||
return show_command_help(ctx.args[0]);
|
return show_command_help(ctx.args[0]);
|
||||||
|
|
||||||
info << std::endl;
|
std::cout << std::endl;
|
||||||
maketitle("DropShell version " + VERSION);
|
maketitle("DropShell version " + VERSION);
|
||||||
info << std::endl;
|
info << std::endl;
|
||||||
info << "A tool for managing remote servers, by " << AUTHOR << std::endl;
|
info << "A tool for managing remote servers, by " << AUTHOR << std::endl;
|
||||||
@ -120,16 +138,17 @@ int help_handler(const CommandContext& ctx) {
|
|||||||
{
|
{
|
||||||
// show more!
|
// show more!
|
||||||
show_command("list");
|
show_command("list");
|
||||||
std::cout << std::endl;
|
info << std::endl;
|
||||||
show_command("install");
|
show_command("install");
|
||||||
show_command("uninstall");
|
show_command("uninstall");
|
||||||
show_command("nuke");
|
show_command("nuke");
|
||||||
std::cout << std::endl;
|
info << std::endl;
|
||||||
show_command("start");
|
show_command("start");
|
||||||
show_command("stop");
|
show_command("stop");
|
||||||
std::cout << std::endl;
|
info << std::endl;
|
||||||
show_command("ssh");
|
show_command("ssh");
|
||||||
std::cout << std::endl;
|
info << std::endl;
|
||||||
|
show_command("create-service");
|
||||||
}
|
}
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
@ -42,7 +42,7 @@ namespace dropshell
|
|||||||
std::lock_guard<std::mutex> lock(output_mutex);
|
std::lock_guard<std::mutex> lock(output_mutex);
|
||||||
if (c == EOF)
|
if (c == EOF)
|
||||||
return !EOF;
|
return !EOF;
|
||||||
if (at_line_start_ && c != '\n')
|
if (at_line_start_) // && c != '\n')
|
||||||
{
|
{
|
||||||
dest_ << GREY << tag_ << RESET << ' ' << colour_;
|
dest_ << GREY << tag_ << RESET << ' ' << colour_;
|
||||||
at_line_start_ = false;
|
at_line_start_ = false;
|
||||||
|
@ -7,6 +7,8 @@
|
|||||||
#include <filesystem>
|
#include <filesystem>
|
||||||
#include <regex>
|
#include <regex>
|
||||||
#include <random>
|
#include <random>
|
||||||
|
#include <sys/ioctl.h>
|
||||||
|
#include <unistd.h>
|
||||||
|
|
||||||
namespace dropshell {
|
namespace dropshell {
|
||||||
|
|
||||||
@ -388,4 +390,46 @@ std::string substitute_provided_key_value_pairs(std::string str, const std::map<
|
|||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int get_console_width()
|
||||||
|
{
|
||||||
|
struct winsize w;
|
||||||
|
if (ioctl(STDOUT_FILENO, TIOCGWINSZ, &w) == 0) {
|
||||||
|
return w.ws_col;
|
||||||
|
}
|
||||||
|
// Fallback to a reasonable default if we can't get the width
|
||||||
|
return 80;
|
||||||
|
}
|
||||||
|
|
||||||
|
std::string remove_return(std::string str)
|
||||||
|
{
|
||||||
|
str.erase(std::remove(str.begin(), str.end(), '\n'), str.end());
|
||||||
|
return str;
|
||||||
|
}
|
||||||
|
|
||||||
|
std::string get_line_wrap(std::string &src, int maxchars)
|
||||||
|
{
|
||||||
|
if (src.empty())
|
||||||
|
return "";
|
||||||
|
|
||||||
|
if (src.length() <= maxchars)
|
||||||
|
{
|
||||||
|
std::string out = src;
|
||||||
|
src.erase();
|
||||||
|
return remove_return(out) + '\n';
|
||||||
|
}
|
||||||
|
|
||||||
|
// find last whitespace up to but not more than maxchars
|
||||||
|
size_t grab_to=maxchars;
|
||||||
|
size_t lastreturn = src.rfind('\n', maxchars);
|
||||||
|
size_t lastspace = src.rfind(' ', maxchars);
|
||||||
|
if (lastreturn != std::string::npos)
|
||||||
|
grab_to = lastreturn;
|
||||||
|
else if (lastspace != std::string::npos)
|
||||||
|
grab_to = lastspace;
|
||||||
|
|
||||||
|
std::string out = src.substr(0, grab_to);
|
||||||
|
src = src.substr(grab_to + 1);
|
||||||
|
return remove_return(out) + '\n';
|
||||||
|
}
|
||||||
|
|
||||||
} // namespace dropshell
|
} // namespace dropshell
|
@ -55,4 +55,8 @@ std::string center_align(const std::string & str, int width);
|
|||||||
std::string replace_with_environment_variables_like_bash(std::string str);
|
std::string replace_with_environment_variables_like_bash(std::string str);
|
||||||
std::string substitute_provided_key_value_pairs(std::string str, const std::map<std::string, std::string> & env_vars);
|
std::string substitute_provided_key_value_pairs(std::string str, const std::map<std::string, std::string> & env_vars);
|
||||||
|
|
||||||
|
int get_console_width();
|
||||||
|
|
||||||
|
std::string get_line_wrap(std::string & src, int maxchars);
|
||||||
|
|
||||||
} // namespace dropshell
|
} // namespace dropshell
|
Loading…
x
Reference in New Issue
Block a user