Mercurial > irccd
comparison irccdctl/cli.cpp @ 451:1fdedd2977d2
Irccdctl: implement rule-move
author | David Demelier <markand@malikania.fr> |
---|---|
date | Fri, 07 Jul 2017 18:03:18 +0200 |
parents | c8c68d4bf555 |
children | 2170aa0e38aa |
comparison
equal
deleted
inserted
replaced
450:c8c68d4bf555 | 451:1fdedd2977d2 |
---|---|
978 { "command", "rule-remove" }, | 978 { "command", "rule-remove" }, |
979 { "index", index } | 979 { "index", index } |
980 }); | 980 }); |
981 | 981 |
982 check(result); | 982 check(result); |
983 } | |
984 | |
985 /* | |
986 * RuleMoveCli. | |
987 * ------------------------------------------------------------------ | |
988 */ | |
989 | |
990 RuleMoveCli::RuleMoveCli() | |
991 : Cli("rule-move", | |
992 "move a rule to a new position", | |
993 "rule-move source destination", | |
994 "Move a rule from the given source at the specified destination index.\n\n" | |
995 "The rule will replace the existing one at the given destination moving\ndown every " | |
996 "other rules. If destination is greater or equal the number of rules,\nthe rule " | |
997 "is moved to the end.\n\n" | |
998 "Example:\n" | |
999 "\tirccdctl rule-move 0 5\n" | |
1000 "\tirccdctl rule-move 4 3") | |
1001 { | |
1002 } | |
1003 | |
1004 void RuleMoveCli::exec(Irccdctl &irccdctl, const std::vector<std::string> &args) | |
1005 { | |
1006 if (args.size() < 2) | |
1007 throw std::invalid_argument("rule-move requires 2 arguments"); | |
1008 | |
1009 int from = 0; | |
1010 int to = 0; | |
1011 | |
1012 try { | |
1013 from = std::stoi(args[0]); | |
1014 to = std::stoi(args[1]); | |
1015 } catch (...) { | |
1016 throw std::invalid_argument("invalid number"); | |
1017 } | |
1018 | |
1019 check(request(irccdctl, { | |
1020 { "command", "rule-move" }, | |
1021 { "from", from }, | |
1022 { "to", to } | |
1023 })); | |
983 } | 1024 } |
984 | 1025 |
985 /* | 1026 /* |
986 * WatchCli. | 1027 * WatchCli. |
987 * ------------------------------------------------------------------ | 1028 * ------------------------------------------------------------------ |