mirror of
https://github.com/profanity-im/profanity.git
synced 2024-12-04 14:46:46 -05:00
Show message when alias already exists in /alias add
This commit is contained in:
parent
8dbe300d72
commit
e089ffb15c
@ -1834,8 +1834,11 @@ cmd_alias(gchar **args, struct cmd_help_t help)
|
|||||||
cons_show("Usage: %s", help.usage);
|
cons_show("Usage: %s", help.usage);
|
||||||
return TRUE;
|
return TRUE;
|
||||||
} else {
|
} else {
|
||||||
prefs_add_alias(alias, value);
|
if (prefs_add_alias(alias, value) == TRUE) {
|
||||||
cons_show("Command alias added /%s -> %s", alias, value);
|
cons_show("Command alias added /%s -> %s", alias, value);
|
||||||
|
} else {
|
||||||
|
cons_show("Command alias /%s already exists.", alias);
|
||||||
|
}
|
||||||
return TRUE;
|
return TRUE;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -260,11 +260,16 @@ prefs_set_autoaway_time(gint value)
|
|||||||
_save_prefs();
|
_save_prefs();
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
gboolean
|
||||||
prefs_add_alias(const char * const name, const char * const value)
|
prefs_add_alias(const char * const name, const char * const value)
|
||||||
{
|
{
|
||||||
|
if (g_key_file_has_key(prefs, PREF_GROUP_ALIAS, name, NULL)) {
|
||||||
|
return FALSE;
|
||||||
|
} else {
|
||||||
g_key_file_set_string(prefs, PREF_GROUP_ALIAS, name, value);
|
g_key_file_set_string(prefs, PREF_GROUP_ALIAS, name, value);
|
||||||
_save_prefs();
|
_save_prefs();
|
||||||
|
return TRUE;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
char *
|
char *
|
||||||
|
@ -97,7 +97,7 @@ void prefs_set_autoaway_time(gint value);
|
|||||||
|
|
||||||
void prefs_add_login(const char *jid);
|
void prefs_add_login(const char *jid);
|
||||||
|
|
||||||
void prefs_add_alias(const char * const name, const char * const value);
|
gboolean prefs_add_alias(const char * const name, const char * const value);
|
||||||
gboolean prefs_remove_alias(const char * const name);
|
gboolean prefs_remove_alias(const char * const name);
|
||||||
char* prefs_get_alias(const char * const name);
|
char* prefs_get_alias(const char * const name);
|
||||||
GList* prefs_get_aliases(void);
|
GList* prefs_get_aliases(void);
|
||||||
|
@ -94,6 +94,22 @@ void cmd_alias_add_adds_alias(void **state)
|
|||||||
free(help);
|
free(help);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void cmd_alias_add_shows_message_when_exists(void **state)
|
||||||
|
{
|
||||||
|
mock_cons_show();
|
||||||
|
CommandHelp *help = malloc(sizeof(CommandHelp));
|
||||||
|
gchar *args[] = { "add", "hc", "/help commands", NULL };
|
||||||
|
|
||||||
|
prefs_add_alias("hc", "/help commands");
|
||||||
|
|
||||||
|
expect_cons_show("Command alias /hc already exists.");
|
||||||
|
|
||||||
|
gboolean result = cmd_alias(args, *help);
|
||||||
|
assert_true(result);
|
||||||
|
|
||||||
|
free(help);
|
||||||
|
}
|
||||||
|
|
||||||
void cmd_alias_remove_removes_alias(void **state)
|
void cmd_alias_remove_removes_alias(void **state)
|
||||||
{
|
{
|
||||||
mock_cons_show();
|
mock_cons_show();
|
||||||
|
@ -3,6 +3,7 @@ void cmd_alias_add_shows_usage_when_no_value(void **state);
|
|||||||
void cmd_alias_remove_shows_usage_when_no_args(void **state);
|
void cmd_alias_remove_shows_usage_when_no_args(void **state);
|
||||||
void cmd_alias_show_usage_when_invalid_subcmd(void **state);
|
void cmd_alias_show_usage_when_invalid_subcmd(void **state);
|
||||||
void cmd_alias_add_adds_alias(void **state);
|
void cmd_alias_add_adds_alias(void **state);
|
||||||
|
void cmd_alias_add_shows_message_when_exists(void **state);
|
||||||
void cmd_alias_remove_removes_alias(void **state);
|
void cmd_alias_remove_removes_alias(void **state);
|
||||||
void cmd_alias_remove_shows_message_when_no_alias(void **state);
|
void cmd_alias_remove_shows_message_when_no_alias(void **state);
|
||||||
void cmd_alias_list_shows_all_aliases(void **state);
|
void cmd_alias_list_shows_all_aliases(void **state);
|
||||||
|
@ -399,6 +399,9 @@ int main(int argc, char* argv[]) {
|
|||||||
unit_test_setup_teardown(cmd_alias_add_adds_alias,
|
unit_test_setup_teardown(cmd_alias_add_adds_alias,
|
||||||
create_config_file,
|
create_config_file,
|
||||||
delete_config_file),
|
delete_config_file),
|
||||||
|
unit_test_setup_teardown(cmd_alias_add_shows_message_when_exists,
|
||||||
|
create_config_file,
|
||||||
|
delete_config_file),
|
||||||
unit_test_setup_teardown(cmd_alias_remove_removes_alias,
|
unit_test_setup_teardown(cmd_alias_remove_removes_alias,
|
||||||
create_config_file,
|
create_config_file,
|
||||||
delete_config_file),
|
delete_config_file),
|
||||||
|
Loading…
Reference in New Issue
Block a user