1
0
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:
James Booth 2014-01-23 22:38:12 +00:00
parent 8dbe300d72
commit e089ffb15c
6 changed files with 34 additions and 6 deletions

View File

@ -1834,8 +1834,11 @@ cmd_alias(gchar **args, struct cmd_help_t help)
cons_show("Usage: %s", help.usage);
return TRUE;
} else {
prefs_add_alias(alias, value);
cons_show("Command alias added /%s -> %s", alias, value);
if (prefs_add_alias(alias, value) == TRUE) {
cons_show("Command alias added /%s -> %s", alias, value);
} else {
cons_show("Command alias /%s already exists.", alias);
}
return TRUE;
}
}

View File

@ -260,11 +260,16 @@ prefs_set_autoaway_time(gint value)
_save_prefs();
}
void
gboolean
prefs_add_alias(const char * const name, const char * const value)
{
g_key_file_set_string(prefs, PREF_GROUP_ALIAS, name, value);
_save_prefs();
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);
_save_prefs();
return TRUE;
}
}
char *

View File

@ -97,7 +97,7 @@ void prefs_set_autoaway_time(gint value);
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);
char* prefs_get_alias(const char * const name);
GList* prefs_get_aliases(void);

View File

@ -94,6 +94,22 @@ void cmd_alias_add_adds_alias(void **state)
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)
{
mock_cons_show();

View File

@ -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_show_usage_when_invalid_subcmd(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_shows_message_when_no_alias(void **state);
void cmd_alias_list_shows_all_aliases(void **state);

View File

@ -399,6 +399,9 @@ int main(int argc, char* argv[]) {
unit_test_setup_teardown(cmd_alias_add_adds_alias,
create_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,
create_config_file,
delete_config_file),