meta: replace bluelib with fx
This commit is contained in:
@@ -0,0 +1,118 @@
|
||||
#include "../commands.h"
|
||||
|
||||
#include <fx/cmdline/cmd.h>
|
||||
#include <fx/error.h>
|
||||
#include <ropkg/repo-mgmt.h>
|
||||
|
||||
enum {
|
||||
OPT_NAME,
|
||||
OPT_NAME_VALUE,
|
||||
OPT_DESCRIPTION,
|
||||
OPT_DESCRIPTION_VALUE,
|
||||
OPT_REPO,
|
||||
OPT_REPO_PATH,
|
||||
};
|
||||
|
||||
static int channel_add(
|
||||
const fx_command *self,
|
||||
const fx_arglist *opt,
|
||||
const fx_array *args)
|
||||
{
|
||||
const char *root_path = NULL;
|
||||
const char *channel_name = NULL;
|
||||
|
||||
fx_arglist_get_string(opt, OPT_REPO, OPT_REPO_PATH, 0, &root_path);
|
||||
fx_arglist_get_string(opt, OPT_NAME, OPT_NAME_VALUE, 0, &channel_name);
|
||||
|
||||
if (!root_path) {
|
||||
fx_arglist_report_missing_args(opt, OPT_REPO, OPT_REPO_PATH, 0);
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (!channel_name) {
|
||||
fx_arglist_report_missing_args(
|
||||
opt,
|
||||
OPT_NAME,
|
||||
OPT_NAME_VALUE,
|
||||
0);
|
||||
return -1;
|
||||
}
|
||||
|
||||
struct ropkg_repo_mgmt *repo = NULL;
|
||||
fx_result result = ropkg_repo_mgmt_open(root_path, &repo);
|
||||
if (fx_result_is_error(result)) {
|
||||
fx_throw(result);
|
||||
return -1;
|
||||
}
|
||||
|
||||
struct ropkg_repo_mgmt_channel *channel = NULL;
|
||||
result = ropkg_repo_mgmt_create_channel(repo, channel_name, &channel);
|
||||
if (fx_result_is_error(result)) {
|
||||
ropkg_repo_mgmt_close(repo);
|
||||
fx_throw(result);
|
||||
return -1;
|
||||
}
|
||||
|
||||
ropkg_repo_mgmt_channel_close(channel);
|
||||
ropkg_repo_mgmt_close(repo);
|
||||
return 0;
|
||||
}
|
||||
|
||||
FX_COMMAND(CMD_CHANNEL_ADD, CMD_CHANNEL)
|
||||
{
|
||||
FX_COMMAND_NAME("add");
|
||||
FX_COMMAND_SHORT_NAME('A');
|
||||
FX_COMMAND_DESC("add a channel to a repository.");
|
||||
FX_COMMAND_FLAGS(FX_COMMAND_SHOW_HELP_BY_DEFAULT);
|
||||
FX_COMMAND_FUNCTION(channel_add);
|
||||
|
||||
FX_COMMAND_HELP_OPTION();
|
||||
|
||||
FX_COMMAND_OPTION(OPT_REPO)
|
||||
{
|
||||
FX_OPTION_LONG_NAME("repo");
|
||||
FX_OPTION_SHORT_NAME('r');
|
||||
FX_OPTION_DESC(
|
||||
"the path to the repository to create the channel in.");
|
||||
|
||||
FX_OPTION_ARG(OPT_REPO_PATH)
|
||||
{
|
||||
FX_ARG_NAME("path");
|
||||
FX_ARG_DESC(
|
||||
"the path to the repository to create the "
|
||||
"channel in.");
|
||||
FX_ARG_NR_VALUES(1);
|
||||
}
|
||||
}
|
||||
|
||||
FX_COMMAND_OPTION(OPT_NAME)
|
||||
{
|
||||
FX_OPTION_LONG_NAME("name");
|
||||
FX_OPTION_SHORT_NAME('n');
|
||||
FX_OPTION_DESC("the name of the channel to create.");
|
||||
|
||||
FX_OPTION_ARG(OPT_NAME_VALUE)
|
||||
{
|
||||
FX_ARG_NAME("name");
|
||||
FX_ARG_DESC("the name of the channel to create.");
|
||||
FX_ARG_NR_VALUES(1);
|
||||
}
|
||||
}
|
||||
|
||||
FX_COMMAND_OPTION(OPT_DESCRIPTION)
|
||||
{
|
||||
FX_OPTION_LONG_NAME("description");
|
||||
FX_OPTION_SHORT_NAME('d');
|
||||
FX_OPTION_DESC(
|
||||
"a human-readable description of the new channel.");
|
||||
|
||||
FX_OPTION_ARG(OPT_DESCRIPTION_VALUE)
|
||||
{
|
||||
FX_ARG_NAME("description");
|
||||
FX_ARG_DESC(
|
||||
"a human-readable description of the new "
|
||||
"channel.");
|
||||
FX_ARG_NR_VALUES(1);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user