2022-04-08 07:52:16 +00:00
|
|
|
#include "ICommand.h"
|
2022-07-20 20:30:16 +00:00
|
|
|
#include <Interpreters/Context.h>
|
2022-04-08 07:52:16 +00:00
|
|
|
|
|
|
|
namespace DB
|
|
|
|
{
|
|
|
|
|
|
|
|
namespace ErrorCodes
|
|
|
|
{
|
|
|
|
extern const int BAD_ARGUMENTS;
|
|
|
|
}
|
|
|
|
|
2022-12-08 17:20:54 +00:00
|
|
|
class CommandListDisks final : public ICommand
|
2022-04-08 07:52:16 +00:00
|
|
|
{
|
|
|
|
public:
|
|
|
|
CommandListDisks()
|
|
|
|
{
|
|
|
|
command_name = "list-disks";
|
|
|
|
description = "List disks names";
|
2022-06-16 17:38:33 +00:00
|
|
|
usage = "list-disks [OPTION]";
|
2022-04-08 07:52:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void processOptions(
|
2022-06-06 11:14:50 +00:00
|
|
|
Poco::Util::LayeredConfiguration &,
|
2022-06-16 17:38:33 +00:00
|
|
|
po::variables_map &) const override
|
|
|
|
{}
|
2022-04-08 07:52:16 +00:00
|
|
|
|
2022-06-16 17:38:33 +00:00
|
|
|
void execute(
|
|
|
|
const std::vector<String> & command_arguments,
|
2023-11-30 03:09:55 +00:00
|
|
|
std::shared_ptr<DiskSelector> &,
|
|
|
|
Poco::Util::LayeredConfiguration & config) override
|
2022-04-08 07:52:16 +00:00
|
|
|
{
|
2022-06-16 17:38:33 +00:00
|
|
|
if (!command_arguments.empty())
|
2022-04-08 07:52:16 +00:00
|
|
|
{
|
|
|
|
printHelpMessage();
|
2023-01-23 21:13:58 +00:00
|
|
|
throw DB::Exception(DB::ErrorCodes::BAD_ARGUMENTS, "Bad Arguments");
|
2022-04-08 07:52:16 +00:00
|
|
|
}
|
|
|
|
|
2023-11-30 03:09:55 +00:00
|
|
|
constexpr auto config_prefix = "storage_configuration.disks";
|
|
|
|
constexpr auto default_disk_name = "default";
|
|
|
|
|
|
|
|
Poco::Util::AbstractConfiguration::Keys keys;
|
|
|
|
config.keys(config_prefix, keys);
|
|
|
|
|
|
|
|
bool has_default_disk = false;
|
|
|
|
|
2023-12-02 23:59:46 +00:00
|
|
|
/// For the output to be ordered
|
|
|
|
std::set<String> disks;
|
|
|
|
|
2023-11-30 03:09:55 +00:00
|
|
|
for (const auto & disk_name : keys)
|
|
|
|
{
|
|
|
|
if (disk_name == default_disk_name)
|
|
|
|
has_default_disk = true;
|
2023-12-02 23:59:46 +00:00
|
|
|
disks.insert(disk_name);
|
2023-11-30 03:09:55 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (!has_default_disk)
|
2023-12-02 23:59:46 +00:00
|
|
|
disks.insert(default_disk_name);
|
|
|
|
|
|
|
|
for (const auto & disk : disks)
|
|
|
|
std::cout << disk << '\n';
|
2022-04-08 07:52:16 +00:00
|
|
|
}
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
std::unique_ptr <DB::ICommand> makeCommandListDisks()
|
|
|
|
{
|
|
|
|
return std::make_unique<DB::CommandListDisks>();
|
|
|
|
}
|