diff --git a/src/com/jdbernard/twitter/TwitterCLI.groovy b/src/com/jdbernard/twitter/TwitterCLI.groovy index ec51d9d..b899873 100644 --- a/src/com/jdbernard/twitter/TwitterCLI.groovy +++ b/src/com/jdbernard/twitter/TwitterCLI.groovy @@ -29,6 +29,11 @@ public class TwitterCLI { private Logger log = LoggerFactory.getLogger(getClass()) + + /* ============================================= */ + /* ======== MAIN METHODS - Entry points ======== */ + /* ============================================= */ + public static void main(String[] args) { TwitterCLI inst = new TwitterCLI(new File(System.getProperty("user.home"), ".gritterrc")) @@ -51,6 +56,10 @@ public class TwitterCLI { nailgunInst.run((context.args as List) as LinkedList) } + /* ===================================== */ + /* ======== CONFIGURATION/SETUP ======== */ + /* ===================================== */ + public static void reconfigure(LinkedList args) { if (nailgunInst == null) main(args as String[]) else { @@ -62,41 +71,6 @@ public class TwitterCLI { } } - static String wrapToWidth(String text, int width, String prefix, String suffix) { - int lastSpaceIdx = 0; - int curLineLength = 0; - int lineStartIdx = 0; - int i = 0; - int actualWidth = width - prefix.length() - suffix.length() - String wrapped = "" - - text = text.replaceAll("[\n\r]", " ") - - for (i = 0; i < text.length(); i++) { - - curLineLength++ - if (curLineLength > actualWidth) { - - if (lastSpaceIdx == -1) // we haven't seen a space on this line - lastSpaceIdx = lineStartIdx + actualWidth - 1 - - wrapped += prefix + text[lineStartIdx.. 1) - wrapped += prefix + text[lineStartIdx.. " + - "..." - return - } - - switch (option) { - case "status": postStatus(args.poll()); break - case "retweet": retweetStatus(args.poll()); break - case "list": createList(args); break - default: postStatus(option) - } - } - - public void set(LinkedList args) { - def option = args.poll() - def value = args.poll() - - log.debug("Processing a 'set' command: option = '{}', value = '{}'", - option, value) - - if (!value) { // note: if option is null, value is null - println color("set", colors.option) + - color(" command requires two options: ", colors.error) + - "gritter set " - return - } - - switch (option) { - case "terminalWidth": terminalWidth = value as int; break - case "colored": colored = value.toLowerCase() ==~ /true|t|on|yes|y/ - break - - default: - println color("No property named ", colors.error) + - color(option, colors.option) + - color(" exists.", colors.error) - } - } - + /** + | Parse a ``show list`` command. Valid options are: + | + | +--------------------+-----------------------------------------------+ + | | *Argument* | *Description* | + | +--------------------+-----------------------------------------------+ + | | ``members`` | Show the members of a given list. This is the | + | | | list of users who's tweets comprise the list. | + | +--------------------+-----------------------------------------------+ + | | ``subscribers`` | Show the subscribers of a given list. This is | + | | | the list of users who are see the list. | + | +--------------------+-----------------------------------------------+ + | | ``subscriptions`` | Show all of the lists a given user is | + | | | subscribed to. | + | +--------------------+-----------------------------------------------+ + | | *list-reference* | Show the timeline for a given list. | + | +--------------------+-----------------------------------------------+ + | + | @param args a {@link java.util.LinkedList} of arguments. + */ public void showList(LinkedList args) { def option = args.poll() @@ -266,6 +323,14 @@ public class TwitterCLI { } } + /** + | Parse a ``show lists`` command. ``show lists`` consumes at most one + | argument, representing a user reference. It shows all of the lists + | owned by the given user. If no user reference is given ``show lists`` + | shows the lists owned by the currently logged in user. + | + | @param args a {@link java.util.LinkedList} of arguments. + */ public void showLists(LinkedList args) { def user = args.poll() @@ -276,6 +341,12 @@ public class TwitterCLI { printLists(twitter.getUserLists(user, -1)) // TODO paging } + /** + | Parse a ``show list members`` command. ``show list members`` consumes + | one argument, a reference to the list in question. + | + | @param args a {@util java.util.LinkedList} of arguments. + */ public void showListMembers(LinkedList args) { def listRef = parseListReference(args) @@ -296,6 +367,12 @@ public class TwitterCLI { printUserList(userList) // TODO paging } + /** + | Parse a ``show list subscribers`` command. ``show list subscribers + | consumes one argument, a reference to the list in question. + | + | @param args a {@util java.util.LinkedList} of arguments. + */ public void showListSubscribers(LinkedList args) { def listRef = parseListReference(args) @@ -314,6 +391,12 @@ public class TwitterCLI { listRef.username, listRef.listId, -1)) // TODO: paging } + /** + | Parse a ``show list members`` command. ``show list members consumes one + | argument, a reference to the list in question. + | + | @param args a {@util java.util.LinkedList} of arguments. + */ public void showListSubscriptions(LinkedList args) { def user = args.poll() @@ -399,6 +482,58 @@ public class TwitterCLI { } } + public void help(LinkedList args) { + + log.debug("Processing a 'help' command.") + } + + public void post(LinkedList args) { + def option = args.poll() + + log.debug("Processing a 'post' command: option = '{}'", option) + + if (!option) { + println color("post", colors.option) + + color(" command requires at least two parameters: ", + colors.error) + "gritter post " + + "..." + return + } + + switch (option) { + case "status": postStatus(args.poll()); break + case "retweet": retweetStatus(args.poll()); break + case "list": createList(args); break + default: postStatus(option) + } + } + + public void set(LinkedList args) { + def option = args.poll() + def value = args.poll() + + log.debug("Processing a 'set' command: option = '{}', value = '{}'", + option, value) + + if (!value) { // note: if option is null, value is null + println color("set", colors.option) + + color(" command requires two options: ", colors.error) + + "gritter set " + return + } + + switch (option) { + case "terminalWidth": terminalWidth = value as int; break + case "colored": colored = value.toLowerCase() ==~ /true|t|on|yes|y/ + break + + default: + println color("No property named ", colors.error) + + color(option, colors.option) + + color(" exists.", colors.error) + } + } + /* ======== WORKER FUNCTIONS ========*/ public void deleteListMember(LinkedList args) { @@ -731,4 +866,38 @@ public class TwitterCLI { return color.toString() + message + (existing ?: resetColor()) } + static String wrapToWidth(String text, int width, String prefix, String suffix) { + int lastSpaceIdx = 0; + int curLineLength = 0; + int lineStartIdx = 0; + int i = 0; + int actualWidth = width - prefix.length() - suffix.length() + String wrapped = "" + + text = text.replaceAll("[\n\r]", " ") + + for (i = 0; i < text.length(); i++) { + + curLineLength++ + if (curLineLength > actualWidth) { + + if (lastSpaceIdx == -1) // we haven't seen a space on this line + lastSpaceIdx = lineStartIdx + actualWidth - 1 + + wrapped += prefix + text[lineStartIdx.. 1) + wrapped += prefix + text[lineStartIdx..