2010-11-05 23:10:03 +00:00
|
|
|
package com.jdbernard.twitter
|
|
|
|
|
Added color, better nailgun support, new argument processing model, base commands.
ConsoleColor
Added to support for terminal colors by using ANSI escape codes.
Basically cross-platform (as close as we're going to get with Java's API)
TwitterCLI
Added colored output and configurable settings controlling it.
Created a specific Nailgun entry-point. When using Nailgun the Twitter
object is cached in the JVM so that it doesn't need to be recreated
each time a call is made. This also means that settings changed from the
command line persist until the Nailgun server is reset.
Added functionality to wrap the status nicely to a set width (used for
printing timelines).
Arguments are not processed internally as a Queue, so each command/option
is popped off the queue before it is processed.
Added and updated base commands:
help - not implemented, will be used to display online help about a
command.
post - Basic implementation added. It checks the length of the status,
and asks for confirmation from the user before posting.
reconfigure - If a Nailgun server is being used, it is useful to be
able to reconfigure the client without restarting the nailgun
server. This scraps the current instance cached by the ng
server and creates a fresh instance.
set - Allows the user to set a configurable value on the command line.
So far, only the following configurable values are available:
terminalWidth - integer, used for calculating text wrapping.
colored - boolean, enables or disables colored output.
show - not implemented, will be used to show various information
2010-11-06 21:24:29 +00:00
|
|
|
import com.martiansoftware.nailgun.NGContext
|
2010-11-09 15:26:05 +00:00
|
|
|
import org.slf4j.Logger
|
|
|
|
import org.slf4j.LoggerFactory
|
|
|
|
import twitter4j.Paging
|
|
|
|
import twitter4j.Status
|
2010-11-05 23:10:03 +00:00
|
|
|
import twitter4j.Twitter
|
|
|
|
import twitter4j.TwitterFactory
|
|
|
|
import twitter4j.conf.Configuration
|
|
|
|
import twitter4j.conf.PropertyConfiguration
|
|
|
|
|
|
|
|
public class TwitterCLI {
|
|
|
|
|
Added color, better nailgun support, new argument processing model, base commands.
ConsoleColor
Added to support for terminal colors by using ANSI escape codes.
Basically cross-platform (as close as we're going to get with Java's API)
TwitterCLI
Added colored output and configurable settings controlling it.
Created a specific Nailgun entry-point. When using Nailgun the Twitter
object is cached in the JVM so that it doesn't need to be recreated
each time a call is made. This also means that settings changed from the
command line persist until the Nailgun server is reset.
Added functionality to wrap the status nicely to a set width (used for
printing timelines).
Arguments are not processed internally as a Queue, so each command/option
is popped off the queue before it is processed.
Added and updated base commands:
help - not implemented, will be used to display online help about a
command.
post - Basic implementation added. It checks the length of the status,
and asks for confirmation from the user before posting.
reconfigure - If a Nailgun server is being used, it is useful to be
able to reconfigure the client without restarting the nailgun
server. This scraps the current instance cached by the ng
server and creates a fresh instance.
set - Allows the user to set a configurable value on the command line.
So far, only the following configurable values are available:
terminalWidth - integer, used for calculating text wrapping.
colored - boolean, enables or disables colored output.
show - not implemented, will be used to show various information
2010-11-06 21:24:29 +00:00
|
|
|
private static String EOL = System.getProperty("line.separator")
|
|
|
|
|
2010-11-06 15:52:52 +00:00
|
|
|
private static TwitterCLI nailgunInst
|
|
|
|
private Twitter twitter
|
2010-11-05 23:10:03 +00:00
|
|
|
|
Added color, better nailgun support, new argument processing model, base commands.
ConsoleColor
Added to support for terminal colors by using ANSI escape codes.
Basically cross-platform (as close as we're going to get with Java's API)
TwitterCLI
Added colored output and configurable settings controlling it.
Created a specific Nailgun entry-point. When using Nailgun the Twitter
object is cached in the JVM so that it doesn't need to be recreated
each time a call is made. This also means that settings changed from the
command line persist until the Nailgun server is reset.
Added functionality to wrap the status nicely to a set width (used for
printing timelines).
Arguments are not processed internally as a Queue, so each command/option
is popped off the queue before it is processed.
Added and updated base commands:
help - not implemented, will be used to display online help about a
command.
post - Basic implementation added. It checks the length of the status,
and asks for confirmation from the user before posting.
reconfigure - If a Nailgun server is being used, it is useful to be
able to reconfigure the client without restarting the nailgun
server. This scraps the current instance cached by the ng
server and creates a fresh instance.
set - Allows the user to set a configurable value on the command line.
So far, only the following configurable values are available:
terminalWidth - integer, used for calculating text wrapping.
colored - boolean, enables or disables colored output.
show - not implemented, will be used to show various information
2010-11-06 21:24:29 +00:00
|
|
|
private Scanner stdin
|
|
|
|
|
|
|
|
private Map colors = [:]
|
|
|
|
|
|
|
|
private int terminalWidth
|
|
|
|
private boolean colored
|
2010-11-09 22:53:44 +00:00
|
|
|
private boolean printStatusTimestamps
|
Added color, better nailgun support, new argument processing model, base commands.
ConsoleColor
Added to support for terminal colors by using ANSI escape codes.
Basically cross-platform (as close as we're going to get with Java's API)
TwitterCLI
Added colored output and configurable settings controlling it.
Created a specific Nailgun entry-point. When using Nailgun the Twitter
object is cached in the JVM so that it doesn't need to be recreated
each time a call is made. This also means that settings changed from the
command line persist until the Nailgun server is reset.
Added functionality to wrap the status nicely to a set width (used for
printing timelines).
Arguments are not processed internally as a Queue, so each command/option
is popped off the queue before it is processed.
Added and updated base commands:
help - not implemented, will be used to display online help about a
command.
post - Basic implementation added. It checks the length of the status,
and asks for confirmation from the user before posting.
reconfigure - If a Nailgun server is being used, it is useful to be
able to reconfigure the client without restarting the nailgun
server. This scraps the current instance cached by the ng
server and creates a fresh instance.
set - Allows the user to set a configurable value on the command line.
So far, only the following configurable values are available:
terminalWidth - integer, used for calculating text wrapping.
colored - boolean, enables or disables colored output.
show - not implemented, will be used to show various information
2010-11-06 21:24:29 +00:00
|
|
|
|
2010-11-09 15:26:05 +00:00
|
|
|
private Logger log = LoggerFactory.getLogger(getClass())
|
|
|
|
|
2010-11-05 23:10:03 +00:00
|
|
|
public static void main(String[] args) {
|
2010-11-06 15:52:52 +00:00
|
|
|
TwitterCLI inst = new TwitterCLI(new File(System.getProperty("user.home"),
|
2010-11-09 15:26:05 +00:00
|
|
|
".gritterrc"))
|
2010-11-05 23:10:03 +00:00
|
|
|
|
2010-11-09 15:26:05 +00:00
|
|
|
inst.run((args as List) as LinkedList)
|
2010-11-06 15:52:52 +00:00
|
|
|
}
|
2010-11-05 23:10:03 +00:00
|
|
|
|
Added color, better nailgun support, new argument processing model, base commands.
ConsoleColor
Added to support for terminal colors by using ANSI escape codes.
Basically cross-platform (as close as we're going to get with Java's API)
TwitterCLI
Added colored output and configurable settings controlling it.
Created a specific Nailgun entry-point. When using Nailgun the Twitter
object is cached in the JVM so that it doesn't need to be recreated
each time a call is made. This also means that settings changed from the
command line persist until the Nailgun server is reset.
Added functionality to wrap the status nicely to a set width (used for
printing timelines).
Arguments are not processed internally as a Queue, so each command/option
is popped off the queue before it is processed.
Added and updated base commands:
help - not implemented, will be used to display online help about a
command.
post - Basic implementation added. It checks the length of the status,
and asks for confirmation from the user before posting.
reconfigure - If a Nailgun server is being used, it is useful to be
able to reconfigure the client without restarting the nailgun
server. This scraps the current instance cached by the ng
server and creates a fresh instance.
set - Allows the user to set a configurable value on the command line.
So far, only the following configurable values are available:
terminalWidth - integer, used for calculating text wrapping.
colored - boolean, enables or disables colored output.
show - not implemented, will be used to show various information
2010-11-06 21:24:29 +00:00
|
|
|
public static void nailMain(NGContext context) {
|
|
|
|
if (nailgunInst == null)
|
|
|
|
nailgunInst = new TwitterCLI(new File(
|
2010-11-09 15:26:05 +00:00
|
|
|
System.getProperty("user.home"), ".gritterrc"))
|
Added color, better nailgun support, new argument processing model, base commands.
ConsoleColor
Added to support for terminal colors by using ANSI escape codes.
Basically cross-platform (as close as we're going to get with Java's API)
TwitterCLI
Added colored output and configurable settings controlling it.
Created a specific Nailgun entry-point. When using Nailgun the Twitter
object is cached in the JVM so that it doesn't need to be recreated
each time a call is made. This also means that settings changed from the
command line persist until the Nailgun server is reset.
Added functionality to wrap the status nicely to a set width (used for
printing timelines).
Arguments are not processed internally as a Queue, so each command/option
is popped off the queue before it is processed.
Added and updated base commands:
help - not implemented, will be used to display online help about a
command.
post - Basic implementation added. It checks the length of the status,
and asks for confirmation from the user before posting.
reconfigure - If a Nailgun server is being used, it is useful to be
able to reconfigure the client without restarting the nailgun
server. This scraps the current instance cached by the ng
server and creates a fresh instance.
set - Allows the user to set a configurable value on the command line.
So far, only the following configurable values are available:
terminalWidth - integer, used for calculating text wrapping.
colored - boolean, enables or disables colored output.
show - not implemented, will be used to show various information
2010-11-06 21:24:29 +00:00
|
|
|
else
|
|
|
|
nailgunInst.stdin = new Scanner(context.in)
|
2010-11-05 23:10:03 +00:00
|
|
|
|
Added color, better nailgun support, new argument processing model, base commands.
ConsoleColor
Added to support for terminal colors by using ANSI escape codes.
Basically cross-platform (as close as we're going to get with Java's API)
TwitterCLI
Added colored output and configurable settings controlling it.
Created a specific Nailgun entry-point. When using Nailgun the Twitter
object is cached in the JVM so that it doesn't need to be recreated
each time a call is made. This also means that settings changed from the
command line persist until the Nailgun server is reset.
Added functionality to wrap the status nicely to a set width (used for
printing timelines).
Arguments are not processed internally as a Queue, so each command/option
is popped off the queue before it is processed.
Added and updated base commands:
help - not implemented, will be used to display online help about a
command.
post - Basic implementation added. It checks the length of the status,
and asks for confirmation from the user before posting.
reconfigure - If a Nailgun server is being used, it is useful to be
able to reconfigure the client without restarting the nailgun
server. This scraps the current instance cached by the ng
server and creates a fresh instance.
set - Allows the user to set a configurable value on the command line.
So far, only the following configurable values are available:
terminalWidth - integer, used for calculating text wrapping.
colored - boolean, enables or disables colored output.
show - not implemented, will be used to show various information
2010-11-06 21:24:29 +00:00
|
|
|
nailgunInst.
|
2010-11-09 15:26:05 +00:00
|
|
|
nailgunInst.run((context.args as List) as LinkedList)
|
2010-11-05 23:10:03 +00:00
|
|
|
}
|
|
|
|
|
2010-11-09 15:26:05 +00:00
|
|
|
public static void reconfigure(LinkedList args) {
|
Added color, better nailgun support, new argument processing model, base commands.
ConsoleColor
Added to support for terminal colors by using ANSI escape codes.
Basically cross-platform (as close as we're going to get with Java's API)
TwitterCLI
Added colored output and configurable settings controlling it.
Created a specific Nailgun entry-point. When using Nailgun the Twitter
object is cached in the JVM so that it doesn't need to be recreated
each time a call is made. This also means that settings changed from the
command line persist until the Nailgun server is reset.
Added functionality to wrap the status nicely to a set width (used for
printing timelines).
Arguments are not processed internally as a Queue, so each command/option
is popped off the queue before it is processed.
Added and updated base commands:
help - not implemented, will be used to display online help about a
command.
post - Basic implementation added. It checks the length of the status,
and asks for confirmation from the user before posting.
reconfigure - If a Nailgun server is being used, it is useful to be
able to reconfigure the client without restarting the nailgun
server. This scraps the current instance cached by the ng
server and creates a fresh instance.
set - Allows the user to set a configurable value on the command line.
So far, only the following configurable values are available:
terminalWidth - integer, used for calculating text wrapping.
colored - boolean, enables or disables colored output.
show - not implemented, will be used to show various information
2010-11-06 21:24:29 +00:00
|
|
|
if (nailgunInst == null) main(args as String[])
|
|
|
|
else {
|
|
|
|
nailgunInst = null
|
|
|
|
nailgunInst = new TwitterCLI(new File(
|
2010-11-09 15:26:05 +00:00
|
|
|
System.getProperty("user.home"), ".gritterrc"))
|
Added color, better nailgun support, new argument processing model, base commands.
ConsoleColor
Added to support for terminal colors by using ANSI escape codes.
Basically cross-platform (as close as we're going to get with Java's API)
TwitterCLI
Added colored output and configurable settings controlling it.
Created a specific Nailgun entry-point. When using Nailgun the Twitter
object is cached in the JVM so that it doesn't need to be recreated
each time a call is made. This also means that settings changed from the
command line persist until the Nailgun server is reset.
Added functionality to wrap the status nicely to a set width (used for
printing timelines).
Arguments are not processed internally as a Queue, so each command/option
is popped off the queue before it is processed.
Added and updated base commands:
help - not implemented, will be used to display online help about a
command.
post - Basic implementation added. It checks the length of the status,
and asks for confirmation from the user before posting.
reconfigure - If a Nailgun server is being used, it is useful to be
able to reconfigure the client without restarting the nailgun
server. This scraps the current instance cached by the ng
server and creates a fresh instance.
set - Allows the user to set a configurable value on the command line.
So far, only the following configurable values are available:
terminalWidth - integer, used for calculating text wrapping.
colored - boolean, enables or disables colored output.
show - not implemented, will be used to show various information
2010-11-06 21:24:29 +00:00
|
|
|
|
|
|
|
nailgunInst.run(args)
|
|
|
|
}
|
2010-11-05 23:10:03 +00:00
|
|
|
}
|
|
|
|
|
Added color, better nailgun support, new argument processing model, base commands.
ConsoleColor
Added to support for terminal colors by using ANSI escape codes.
Basically cross-platform (as close as we're going to get with Java's API)
TwitterCLI
Added colored output and configurable settings controlling it.
Created a specific Nailgun entry-point. When using Nailgun the Twitter
object is cached in the JVM so that it doesn't need to be recreated
each time a call is made. This also means that settings changed from the
command line persist until the Nailgun server is reset.
Added functionality to wrap the status nicely to a set width (used for
printing timelines).
Arguments are not processed internally as a Queue, so each command/option
is popped off the queue before it is processed.
Added and updated base commands:
help - not implemented, will be used to display online help about a
command.
post - Basic implementation added. It checks the length of the status,
and asks for confirmation from the user before posting.
reconfigure - If a Nailgun server is being used, it is useful to be
able to reconfigure the client without restarting the nailgun
server. This scraps the current instance cached by the ng
server and creates a fresh instance.
set - Allows the user to set a configurable value on the command line.
So far, only the following configurable values are available:
terminalWidth - integer, used for calculating text wrapping.
colored - boolean, enables or disables colored output.
show - not implemented, will be used to show various information
2010-11-06 21:24:29 +00:00
|
|
|
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 = ""
|
2010-11-05 23:10:03 +00:00
|
|
|
|
Added color, better nailgun support, new argument processing model, base commands.
ConsoleColor
Added to support for terminal colors by using ANSI escape codes.
Basically cross-platform (as close as we're going to get with Java's API)
TwitterCLI
Added colored output and configurable settings controlling it.
Created a specific Nailgun entry-point. When using Nailgun the Twitter
object is cached in the JVM so that it doesn't need to be recreated
each time a call is made. This also means that settings changed from the
command line persist until the Nailgun server is reset.
Added functionality to wrap the status nicely to a set width (used for
printing timelines).
Arguments are not processed internally as a Queue, so each command/option
is popped off the queue before it is processed.
Added and updated base commands:
help - not implemented, will be used to display online help about a
command.
post - Basic implementation added. It checks the length of the status,
and asks for confirmation from the user before posting.
reconfigure - If a Nailgun server is being used, it is useful to be
able to reconfigure the client without restarting the nailgun
server. This scraps the current instance cached by the ng
server and creates a fresh instance.
set - Allows the user to set a configurable value on the command line.
So far, only the following configurable values are available:
terminalWidth - integer, used for calculating text wrapping.
colored - boolean, enables or disables colored output.
show - not implemented, will be used to show various information
2010-11-06 21:24:29 +00:00
|
|
|
text = text.replaceAll("[\n\r]", " ")
|
2010-11-05 23:10:03 +00:00
|
|
|
|
Added color, better nailgun support, new argument processing model, base commands.
ConsoleColor
Added to support for terminal colors by using ANSI escape codes.
Basically cross-platform (as close as we're going to get with Java's API)
TwitterCLI
Added colored output and configurable settings controlling it.
Created a specific Nailgun entry-point. When using Nailgun the Twitter
object is cached in the JVM so that it doesn't need to be recreated
each time a call is made. This also means that settings changed from the
command line persist until the Nailgun server is reset.
Added functionality to wrap the status nicely to a set width (used for
printing timelines).
Arguments are not processed internally as a Queue, so each command/option
is popped off the queue before it is processed.
Added and updated base commands:
help - not implemented, will be used to display online help about a
command.
post - Basic implementation added. It checks the length of the status,
and asks for confirmation from the user before posting.
reconfigure - If a Nailgun server is being used, it is useful to be
able to reconfigure the client without restarting the nailgun
server. This scraps the current instance cached by the ng
server and creates a fresh instance.
set - Allows the user to set a configurable value on the command line.
So far, only the following configurable values are available:
terminalWidth - integer, used for calculating text wrapping.
colored - boolean, enables or disables colored output.
show - not implemented, will be used to show various information
2010-11-06 21:24:29 +00:00
|
|
|
for (i = 0; i < text.length(); i++) {
|
|
|
|
|
|
|
|
curLineLength++
|
|
|
|
if (curLineLength > actualWidth) {
|
2010-11-09 15:26:05 +00:00
|
|
|
|
|
|
|
if (lastSpaceIdx == -1) // we haven't seen a space on this line
|
|
|
|
lastSpaceIdx = lineStartIdx + actualWidth - 1
|
|
|
|
|
Added color, better nailgun support, new argument processing model, base commands.
ConsoleColor
Added to support for terminal colors by using ANSI escape codes.
Basically cross-platform (as close as we're going to get with Java's API)
TwitterCLI
Added colored output and configurable settings controlling it.
Created a specific Nailgun entry-point. When using Nailgun the Twitter
object is cached in the JVM so that it doesn't need to be recreated
each time a call is made. This also means that settings changed from the
command line persist until the Nailgun server is reset.
Added functionality to wrap the status nicely to a set width (used for
printing timelines).
Arguments are not processed internally as a Queue, so each command/option
is popped off the queue before it is processed.
Added and updated base commands:
help - not implemented, will be used to display online help about a
command.
post - Basic implementation added. It checks the length of the status,
and asks for confirmation from the user before posting.
reconfigure - If a Nailgun server is being used, it is useful to be
able to reconfigure the client without restarting the nailgun
server. This scraps the current instance cached by the ng
server and creates a fresh instance.
set - Allows the user to set a configurable value on the command line.
So far, only the following configurable values are available:
terminalWidth - integer, used for calculating text wrapping.
colored - boolean, enables or disables colored output.
show - not implemented, will be used to show various information
2010-11-06 21:24:29 +00:00
|
|
|
wrapped += prefix + text[lineStartIdx..<lastSpaceIdx] + suffix + EOL
|
|
|
|
curLineLength = 0
|
|
|
|
lineStartIdx = lastSpaceIdx + 1
|
2010-11-09 15:26:05 +00:00
|
|
|
i = lastSpaceIdx + 1
|
|
|
|
lastSpaceIdx = -1
|
Added color, better nailgun support, new argument processing model, base commands.
ConsoleColor
Added to support for terminal colors by using ANSI escape codes.
Basically cross-platform (as close as we're going to get with Java's API)
TwitterCLI
Added colored output and configurable settings controlling it.
Created a specific Nailgun entry-point. When using Nailgun the Twitter
object is cached in the JVM so that it doesn't need to be recreated
each time a call is made. This also means that settings changed from the
command line persist until the Nailgun server is reset.
Added functionality to wrap the status nicely to a set width (used for
printing timelines).
Arguments are not processed internally as a Queue, so each command/option
is popped off the queue before it is processed.
Added and updated base commands:
help - not implemented, will be used to display online help about a
command.
post - Basic implementation added. It checks the length of the status,
and asks for confirmation from the user before posting.
reconfigure - If a Nailgun server is being used, it is useful to be
able to reconfigure the client without restarting the nailgun
server. This scraps the current instance cached by the ng
server and creates a fresh instance.
set - Allows the user to set a configurable value on the command line.
So far, only the following configurable values are available:
terminalWidth - integer, used for calculating text wrapping.
colored - boolean, enables or disables colored output.
show - not implemented, will be used to show various information
2010-11-06 21:24:29 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (text.charAt(i).isWhitespace())
|
2010-11-09 15:26:05 +00:00
|
|
|
lastSpaceIdx = i
|
Added color, better nailgun support, new argument processing model, base commands.
ConsoleColor
Added to support for terminal colors by using ANSI escape codes.
Basically cross-platform (as close as we're going to get with Java's API)
TwitterCLI
Added colored output and configurable settings controlling it.
Created a specific Nailgun entry-point. When using Nailgun the Twitter
object is cached in the JVM so that it doesn't need to be recreated
each time a call is made. This also means that settings changed from the
command line persist until the Nailgun server is reset.
Added functionality to wrap the status nicely to a set width (used for
printing timelines).
Arguments are not processed internally as a Queue, so each command/option
is popped off the queue before it is processed.
Added and updated base commands:
help - not implemented, will be used to display online help about a
command.
post - Basic implementation added. It checks the length of the status,
and asks for confirmation from the user before posting.
reconfigure - If a Nailgun server is being used, it is useful to be
able to reconfigure the client without restarting the nailgun
server. This scraps the current instance cached by the ng
server and creates a fresh instance.
set - Allows the user to set a configurable value on the command line.
So far, only the following configurable values are available:
terminalWidth - integer, used for calculating text wrapping.
colored - boolean, enables or disables colored output.
show - not implemented, will be used to show various information
2010-11-06 21:24:29 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (i - lineStartIdx > 1)
|
|
|
|
wrapped += prefix + text[lineStartIdx..<text.length()]
|
2010-11-05 23:10:03 +00:00
|
|
|
|
Added color, better nailgun support, new argument processing model, base commands.
ConsoleColor
Added to support for terminal colors by using ANSI escape codes.
Basically cross-platform (as close as we're going to get with Java's API)
TwitterCLI
Added colored output and configurable settings controlling it.
Created a specific Nailgun entry-point. When using Nailgun the Twitter
object is cached in the JVM so that it doesn't need to be recreated
each time a call is made. This also means that settings changed from the
command line persist until the Nailgun server is reset.
Added functionality to wrap the status nicely to a set width (used for
printing timelines).
Arguments are not processed internally as a Queue, so each command/option
is popped off the queue before it is processed.
Added and updated base commands:
help - not implemented, will be used to display online help about a
command.
post - Basic implementation added. It checks the length of the status,
and asks for confirmation from the user before posting.
reconfigure - If a Nailgun server is being used, it is useful to be
able to reconfigure the client without restarting the nailgun
server. This scraps the current instance cached by the ng
server and creates a fresh instance.
set - Allows the user to set a configurable value on the command line.
So far, only the following configurable values are available:
terminalWidth - integer, used for calculating text wrapping.
colored - boolean, enables or disables colored output.
show - not implemented, will be used to show various information
2010-11-06 21:24:29 +00:00
|
|
|
return wrapped
|
|
|
|
}
|
|
|
|
|
2010-11-06 15:52:52 +00:00
|
|
|
public TwitterCLI(File propFile) {
|
|
|
|
|
|
|
|
// load the configuration
|
Added color, better nailgun support, new argument processing model, base commands.
ConsoleColor
Added to support for terminal colors by using ANSI escape codes.
Basically cross-platform (as close as we're going to get with Java's API)
TwitterCLI
Added colored output and configurable settings controlling it.
Created a specific Nailgun entry-point. When using Nailgun the Twitter
object is cached in the JVM so that it doesn't need to be recreated
each time a call is made. This also means that settings changed from the
command line persist until the Nailgun server is reset.
Added functionality to wrap the status nicely to a set width (used for
printing timelines).
Arguments are not processed internally as a Queue, so each command/option
is popped off the queue before it is processed.
Added and updated base commands:
help - not implemented, will be used to display online help about a
command.
post - Basic implementation added. It checks the length of the status,
and asks for confirmation from the user before posting.
reconfigure - If a Nailgun server is being used, it is useful to be
able to reconfigure the client without restarting the nailgun
server. This scraps the current instance cached by the ng
server and creates a fresh instance.
set - Allows the user to set a configurable value on the command line.
So far, only the following configurable values are available:
terminalWidth - integer, used for calculating text wrapping.
colored - boolean, enables or disables colored output.
show - not implemented, will be used to show various information
2010-11-06 21:24:29 +00:00
|
|
|
Properties cfg = new Properties()
|
|
|
|
propFile.withInputStream { is -> cfg.load(is) }
|
2010-11-06 15:52:52 +00:00
|
|
|
|
|
|
|
// create a twitter instance
|
Added color, better nailgun support, new argument processing model, base commands.
ConsoleColor
Added to support for terminal colors by using ANSI escape codes.
Basically cross-platform (as close as we're going to get with Java's API)
TwitterCLI
Added colored output and configurable settings controlling it.
Created a specific Nailgun entry-point. When using Nailgun the Twitter
object is cached in the JVM so that it doesn't need to be recreated
each time a call is made. This also means that settings changed from the
command line persist until the Nailgun server is reset.
Added functionality to wrap the status nicely to a set width (used for
printing timelines).
Arguments are not processed internally as a Queue, so each command/option
is popped off the queue before it is processed.
Added and updated base commands:
help - not implemented, will be used to display online help about a
command.
post - Basic implementation added. It checks the length of the status,
and asks for confirmation from the user before posting.
reconfigure - If a Nailgun server is being used, it is useful to be
able to reconfigure the client without restarting the nailgun
server. This scraps the current instance cached by the ng
server and creates a fresh instance.
set - Allows the user to set a configurable value on the command line.
So far, only the following configurable values are available:
terminalWidth - integer, used for calculating text wrapping.
colored - boolean, enables or disables colored output.
show - not implemented, will be used to show various information
2010-11-06 21:24:29 +00:00
|
|
|
twitter = (new TwitterFactory(new PropertyConfiguration(cfg))).getInstance()
|
|
|
|
|
|
|
|
// configure the colors
|
2010-11-09 22:53:44 +00:00
|
|
|
colors.author = new ConsoleColor(cfg.getProperty("colors.author", "CYAN:false"))
|
Added color, better nailgun support, new argument processing model, base commands.
ConsoleColor
Added to support for terminal colors by using ANSI escape codes.
Basically cross-platform (as close as we're going to get with Java's API)
TwitterCLI
Added colored output and configurable settings controlling it.
Created a specific Nailgun entry-point. When using Nailgun the Twitter
object is cached in the JVM so that it doesn't need to be recreated
each time a call is made. This also means that settings changed from the
command line persist until the Nailgun server is reset.
Added functionality to wrap the status nicely to a set width (used for
printing timelines).
Arguments are not processed internally as a Queue, so each command/option
is popped off the queue before it is processed.
Added and updated base commands:
help - not implemented, will be used to display online help about a
command.
post - Basic implementation added. It checks the length of the status,
and asks for confirmation from the user before posting.
reconfigure - If a Nailgun server is being used, it is useful to be
able to reconfigure the client without restarting the nailgun
server. This scraps the current instance cached by the ng
server and creates a fresh instance.
set - Allows the user to set a configurable value on the command line.
So far, only the following configurable values are available:
terminalWidth - integer, used for calculating text wrapping.
colored - boolean, enables or disables colored output.
show - not implemented, will be used to show various information
2010-11-06 21:24:29 +00:00
|
|
|
colors.mentioned = new ConsoleColor(cfg.getProperty("colors.mentioned", "GREEN:false"))
|
|
|
|
colors.error = new ConsoleColor(cfg.getProperty("colors.error", "RED:true"))
|
|
|
|
colors.option = new ConsoleColor(cfg.getProperty("colors.option", "YELLOW:true"))
|
|
|
|
colors.even = new ConsoleColor(cfg.getProperty("colors.even", "WHITE"))
|
|
|
|
colors.odd = new ConsoleColor(cfg.getProperty("colors.odd", "YELLOW"))
|
2010-11-06 15:52:52 +00:00
|
|
|
|
Added color, better nailgun support, new argument processing model, base commands.
ConsoleColor
Added to support for terminal colors by using ANSI escape codes.
Basically cross-platform (as close as we're going to get with Java's API)
TwitterCLI
Added colored output and configurable settings controlling it.
Created a specific Nailgun entry-point. When using Nailgun the Twitter
object is cached in the JVM so that it doesn't need to be recreated
each time a call is made. This also means that settings changed from the
command line persist until the Nailgun server is reset.
Added functionality to wrap the status nicely to a set width (used for
printing timelines).
Arguments are not processed internally as a Queue, so each command/option
is popped off the queue before it is processed.
Added and updated base commands:
help - not implemented, will be used to display online help about a
command.
post - Basic implementation added. It checks the length of the status,
and asks for confirmation from the user before posting.
reconfigure - If a Nailgun server is being used, it is useful to be
able to reconfigure the client without restarting the nailgun
server. This scraps the current instance cached by the ng
server and creates a fresh instance.
set - Allows the user to set a configurable value on the command line.
So far, only the following configurable values are available:
terminalWidth - integer, used for calculating text wrapping.
colored - boolean, enables or disables colored output.
show - not implemented, will be used to show various information
2010-11-06 21:24:29 +00:00
|
|
|
// configure the terminal width
|
|
|
|
terminalWidth = (System.getenv().COLUMNS ?: cfg.terminalWidth ?: 79) as int
|
|
|
|
|
|
|
|
colored = (cfg.colored ?: 'true') as boolean
|
2010-11-09 22:53:44 +00:00
|
|
|
printStatusTimestamps = (cfg."timeline.printTimestamps" ?: 'true') as boolean
|
Added color, better nailgun support, new argument processing model, base commands.
ConsoleColor
Added to support for terminal colors by using ANSI escape codes.
Basically cross-platform (as close as we're going to get with Java's API)
TwitterCLI
Added colored output and configurable settings controlling it.
Created a specific Nailgun entry-point. When using Nailgun the Twitter
object is cached in the JVM so that it doesn't need to be recreated
each time a call is made. This also means that settings changed from the
command line persist until the Nailgun server is reset.
Added functionality to wrap the status nicely to a set width (used for
printing timelines).
Arguments are not processed internally as a Queue, so each command/option
is popped off the queue before it is processed.
Added and updated base commands:
help - not implemented, will be used to display online help about a
command.
post - Basic implementation added. It checks the length of the status,
and asks for confirmation from the user before posting.
reconfigure - If a Nailgun server is being used, it is useful to be
able to reconfigure the client without restarting the nailgun
server. This scraps the current instance cached by the ng
server and creates a fresh instance.
set - Allows the user to set a configurable value on the command line.
So far, only the following configurable values are available:
terminalWidth - integer, used for calculating text wrapping.
colored - boolean, enables or disables colored output.
show - not implemented, will be used to show various information
2010-11-06 21:24:29 +00:00
|
|
|
|
|
|
|
stdin = new Scanner(System.in)
|
2010-11-06 15:52:52 +00:00
|
|
|
}
|
|
|
|
|
2010-11-09 15:26:05 +00:00
|
|
|
/* ======== PARSING FUNCTIONS ========*/
|
|
|
|
|
|
|
|
public void run(LinkedList args) {
|
2010-11-06 15:52:52 +00:00
|
|
|
if (args.size() < 1) printUsage()
|
|
|
|
|
2010-11-09 15:26:05 +00:00
|
|
|
log.debug("argument list: {}", args)
|
|
|
|
|
Added color, better nailgun support, new argument processing model, base commands.
ConsoleColor
Added to support for terminal colors by using ANSI escape codes.
Basically cross-platform (as close as we're going to get with Java's API)
TwitterCLI
Added colored output and configurable settings controlling it.
Created a specific Nailgun entry-point. When using Nailgun the Twitter
object is cached in the JVM so that it doesn't need to be recreated
each time a call is made. This also means that settings changed from the
command line persist until the Nailgun server is reset.
Added functionality to wrap the status nicely to a set width (used for
printing timelines).
Arguments are not processed internally as a Queue, so each command/option
is popped off the queue before it is processed.
Added and updated base commands:
help - not implemented, will be used to display online help about a
command.
post - Basic implementation added. It checks the length of the status,
and asks for confirmation from the user before posting.
reconfigure - If a Nailgun server is being used, it is useful to be
able to reconfigure the client without restarting the nailgun
server. This scraps the current instance cached by the ng
server and creates a fresh instance.
set - Allows the user to set a configurable value on the command line.
So far, only the following configurable values are available:
terminalWidth - integer, used for calculating text wrapping.
colored - boolean, enables or disables colored output.
show - not implemented, will be used to show various information
2010-11-06 21:24:29 +00:00
|
|
|
while (args.peek()) {
|
|
|
|
def command = args.poll()
|
|
|
|
|
|
|
|
switch (command.toLowerCase()) {
|
2010-11-09 15:26:05 +00:00
|
|
|
case ~/delete|destroy|remove/: delete(args); break
|
|
|
|
case ~/get|show/: get(args); break // get|show
|
|
|
|
case ~/help/: help(args); break // help
|
|
|
|
case ~/post|add|create/: post(args); break // post|add|create
|
|
|
|
case ~/reconfigure/: reconfigure(args); break // reconfigure
|
|
|
|
case ~/set/: set(args); break // set
|
|
|
|
default: // fallthrough
|
|
|
|
args.addFirst(command)
|
|
|
|
get(args)
|
Added color, better nailgun support, new argument processing model, base commands.
ConsoleColor
Added to support for terminal colors by using ANSI escape codes.
Basically cross-platform (as close as we're going to get with Java's API)
TwitterCLI
Added colored output and configurable settings controlling it.
Created a specific Nailgun entry-point. When using Nailgun the Twitter
object is cached in the JVM so that it doesn't need to be recreated
each time a call is made. This also means that settings changed from the
command line persist until the Nailgun server is reset.
Added functionality to wrap the status nicely to a set width (used for
printing timelines).
Arguments are not processed internally as a Queue, so each command/option
is popped off the queue before it is processed.
Added and updated base commands:
help - not implemented, will be used to display online help about a
command.
post - Basic implementation added. It checks the length of the status,
and asks for confirmation from the user before posting.
reconfigure - If a Nailgun server is being used, it is useful to be
able to reconfigure the client without restarting the nailgun
server. This scraps the current instance cached by the ng
server and creates a fresh instance.
set - Allows the user to set a configurable value on the command line.
So far, only the following configurable values are available:
terminalWidth - integer, used for calculating text wrapping.
colored - boolean, enables or disables colored output.
show - not implemented, will be used to show various information
2010-11-06 21:24:29 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-11-09 15:26:05 +00:00
|
|
|
public void delete(LinkedList args) {
|
Added color, better nailgun support, new argument processing model, base commands.
ConsoleColor
Added to support for terminal colors by using ANSI escape codes.
Basically cross-platform (as close as we're going to get with Java's API)
TwitterCLI
Added colored output and configurable settings controlling it.
Created a specific Nailgun entry-point. When using Nailgun the Twitter
object is cached in the JVM so that it doesn't need to be recreated
each time a call is made. This also means that settings changed from the
command line persist until the Nailgun server is reset.
Added functionality to wrap the status nicely to a set width (used for
printing timelines).
Arguments are not processed internally as a Queue, so each command/option
is popped off the queue before it is processed.
Added and updated base commands:
help - not implemented, will be used to display online help about a
command.
post - Basic implementation added. It checks the length of the status,
and asks for confirmation from the user before posting.
reconfigure - If a Nailgun server is being used, it is useful to be
able to reconfigure the client without restarting the nailgun
server. This scraps the current instance cached by the ng
server and creates a fresh instance.
set - Allows the user to set a configurable value on the command line.
So far, only the following configurable values are available:
terminalWidth - integer, used for calculating text wrapping.
colored - boolean, enables or disables colored output.
show - not implemented, will be used to show various information
2010-11-06 21:24:29 +00:00
|
|
|
|
|
|
|
}
|
|
|
|
|
2010-11-09 15:26:05 +00:00
|
|
|
public void get(LinkedList args) {
|
|
|
|
def option = args.poll()
|
Added color, better nailgun support, new argument processing model, base commands.
ConsoleColor
Added to support for terminal colors by using ANSI escape codes.
Basically cross-platform (as close as we're going to get with Java's API)
TwitterCLI
Added colored output and configurable settings controlling it.
Created a specific Nailgun entry-point. When using Nailgun the Twitter
object is cached in the JVM so that it doesn't need to be recreated
each time a call is made. This also means that settings changed from the
command line persist until the Nailgun server is reset.
Added functionality to wrap the status nicely to a set width (used for
printing timelines).
Arguments are not processed internally as a Queue, so each command/option
is popped off the queue before it is processed.
Added and updated base commands:
help - not implemented, will be used to display online help about a
command.
post - Basic implementation added. It checks the length of the status,
and asks for confirmation from the user before posting.
reconfigure - If a Nailgun server is being used, it is useful to be
able to reconfigure the client without restarting the nailgun
server. This scraps the current instance cached by the ng
server and creates a fresh instance.
set - Allows the user to set a configurable value on the command line.
So far, only the following configurable values are available:
terminalWidth - integer, used for calculating text wrapping.
colored - boolean, enables or disables colored output.
show - not implemented, will be used to show various information
2010-11-06 21:24:29 +00:00
|
|
|
|
2010-11-09 15:26:05 +00:00
|
|
|
log.debug("Processing a 'get' command, option = {}.", option)
|
|
|
|
|
|
|
|
switch(option) {
|
|
|
|
case "list": showList(args); break
|
|
|
|
case "lists": showLists(args); break
|
|
|
|
case ~/subs.*/: showSubscriptions(args); break
|
|
|
|
case "timeline": showTimeline(args); break
|
|
|
|
case "user": showUser(args); break
|
|
|
|
default: args.addFirst(option)
|
|
|
|
showTimeline(args)
|
Added color, better nailgun support, new argument processing model, base commands.
ConsoleColor
Added to support for terminal colors by using ANSI escape codes.
Basically cross-platform (as close as we're going to get with Java's API)
TwitterCLI
Added colored output and configurable settings controlling it.
Created a specific Nailgun entry-point. When using Nailgun the Twitter
object is cached in the JVM so that it doesn't need to be recreated
each time a call is made. This also means that settings changed from the
command line persist until the Nailgun server is reset.
Added functionality to wrap the status nicely to a set width (used for
printing timelines).
Arguments are not processed internally as a Queue, so each command/option
is popped off the queue before it is processed.
Added and updated base commands:
help - not implemented, will be used to display online help about a
command.
post - Basic implementation added. It checks the length of the status,
and asks for confirmation from the user before posting.
reconfigure - If a Nailgun server is being used, it is useful to be
able to reconfigure the client without restarting the nailgun
server. This scraps the current instance cached by the ng
server and creates a fresh instance.
set - Allows the user to set a configurable value on the command line.
So far, only the following configurable values are available:
terminalWidth - integer, used for calculating text wrapping.
colored - boolean, enables or disables colored output.
show - not implemented, will be used to show various information
2010-11-06 21:24:29 +00:00
|
|
|
}
|
2010-11-09 15:26:05 +00:00
|
|
|
}
|
Added color, better nailgun support, new argument processing model, base commands.
ConsoleColor
Added to support for terminal colors by using ANSI escape codes.
Basically cross-platform (as close as we're going to get with Java's API)
TwitterCLI
Added colored output and configurable settings controlling it.
Created a specific Nailgun entry-point. When using Nailgun the Twitter
object is cached in the JVM so that it doesn't need to be recreated
each time a call is made. This also means that settings changed from the
command line persist until the Nailgun server is reset.
Added functionality to wrap the status nicely to a set width (used for
printing timelines).
Arguments are not processed internally as a Queue, so each command/option
is popped off the queue before it is processed.
Added and updated base commands:
help - not implemented, will be used to display online help about a
command.
post - Basic implementation added. It checks the length of the status,
and asks for confirmation from the user before posting.
reconfigure - If a Nailgun server is being used, it is useful to be
able to reconfigure the client without restarting the nailgun
server. This scraps the current instance cached by the ng
server and creates a fresh instance.
set - Allows the user to set a configurable value on the command line.
So far, only the following configurable values are available:
terminalWidth - integer, used for calculating text wrapping.
colored - boolean, enables or disables colored output.
show - not implemented, will be used to show various information
2010-11-06 21:24:29 +00:00
|
|
|
|
2010-11-09 15:26:05 +00:00
|
|
|
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 <status|retweet|list> " +
|
|
|
|
"<options>..."
|
Added color, better nailgun support, new argument processing model, base commands.
ConsoleColor
Added to support for terminal colors by using ANSI escape codes.
Basically cross-platform (as close as we're going to get with Java's API)
TwitterCLI
Added colored output and configurable settings controlling it.
Created a specific Nailgun entry-point. When using Nailgun the Twitter
object is cached in the JVM so that it doesn't need to be recreated
each time a call is made. This also means that settings changed from the
command line persist until the Nailgun server is reset.
Added functionality to wrap the status nicely to a set width (used for
printing timelines).
Arguments are not processed internally as a Queue, so each command/option
is popped off the queue before it is processed.
Added and updated base commands:
help - not implemented, will be used to display online help about a
command.
post - Basic implementation added. It checks the length of the status,
and asks for confirmation from the user before posting.
reconfigure - If a Nailgun server is being used, it is useful to be
able to reconfigure the client without restarting the nailgun
server. This scraps the current instance cached by the ng
server and creates a fresh instance.
set - Allows the user to set a configurable value on the command line.
So far, only the following configurable values are available:
terminalWidth - integer, used for calculating text wrapping.
colored - boolean, enables or disables colored output.
show - not implemented, will be used to show various information
2010-11-06 21:24:29 +00:00
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2010-11-09 15:26:05 +00:00
|
|
|
switch (option) {
|
|
|
|
case "status": postStatus(args.poll()); break
|
|
|
|
case "retweet": retweetStatus(args.poll()); break
|
|
|
|
case "list": createList(args); break
|
|
|
|
default: postStatus(option)
|
|
|
|
}
|
Added color, better nailgun support, new argument processing model, base commands.
ConsoleColor
Added to support for terminal colors by using ANSI escape codes.
Basically cross-platform (as close as we're going to get with Java's API)
TwitterCLI
Added colored output and configurable settings controlling it.
Created a specific Nailgun entry-point. When using Nailgun the Twitter
object is cached in the JVM so that it doesn't need to be recreated
each time a call is made. This also means that settings changed from the
command line persist until the Nailgun server is reset.
Added functionality to wrap the status nicely to a set width (used for
printing timelines).
Arguments are not processed internally as a Queue, so each command/option
is popped off the queue before it is processed.
Added and updated base commands:
help - not implemented, will be used to display online help about a
command.
post - Basic implementation added. It checks the length of the status,
and asks for confirmation from the user before posting.
reconfigure - If a Nailgun server is being used, it is useful to be
able to reconfigure the client without restarting the nailgun
server. This scraps the current instance cached by the ng
server and creates a fresh instance.
set - Allows the user to set a configurable value on the command line.
So far, only the following configurable values are available:
terminalWidth - integer, used for calculating text wrapping.
colored - boolean, enables or disables colored output.
show - not implemented, will be used to show various information
2010-11-06 21:24:29 +00:00
|
|
|
}
|
|
|
|
|
2010-11-09 15:26:05 +00:00
|
|
|
public void set(LinkedList args) {
|
Added color, better nailgun support, new argument processing model, base commands.
ConsoleColor
Added to support for terminal colors by using ANSI escape codes.
Basically cross-platform (as close as we're going to get with Java's API)
TwitterCLI
Added colored output and configurable settings controlling it.
Created a specific Nailgun entry-point. When using Nailgun the Twitter
object is cached in the JVM so that it doesn't need to be recreated
each time a call is made. This also means that settings changed from the
command line persist until the Nailgun server is reset.
Added functionality to wrap the status nicely to a set width (used for
printing timelines).
Arguments are not processed internally as a Queue, so each command/option
is popped off the queue before it is processed.
Added and updated base commands:
help - not implemented, will be used to display online help about a
command.
post - Basic implementation added. It checks the length of the status,
and asks for confirmation from the user before posting.
reconfigure - If a Nailgun server is being used, it is useful to be
able to reconfigure the client without restarting the nailgun
server. This scraps the current instance cached by the ng
server and creates a fresh instance.
set - Allows the user to set a configurable value on the command line.
So far, only the following configurable values are available:
terminalWidth - integer, used for calculating text wrapping.
colored - boolean, enables or disables colored output.
show - not implemented, will be used to show various information
2010-11-06 21:24:29 +00:00
|
|
|
def option = args.poll()
|
|
|
|
def value = args.poll()
|
|
|
|
|
2010-11-09 15:26:05 +00:00
|
|
|
log.debug("Processing a 'set' command: option = '{}', value = '{}'",
|
|
|
|
option, value)
|
|
|
|
|
Added color, better nailgun support, new argument processing model, base commands.
ConsoleColor
Added to support for terminal colors by using ANSI escape codes.
Basically cross-platform (as close as we're going to get with Java's API)
TwitterCLI
Added colored output and configurable settings controlling it.
Created a specific Nailgun entry-point. When using Nailgun the Twitter
object is cached in the JVM so that it doesn't need to be recreated
each time a call is made. This also means that settings changed from the
command line persist until the Nailgun server is reset.
Added functionality to wrap the status nicely to a set width (used for
printing timelines).
Arguments are not processed internally as a Queue, so each command/option
is popped off the queue before it is processed.
Added and updated base commands:
help - not implemented, will be used to display online help about a
command.
post - Basic implementation added. It checks the length of the status,
and asks for confirmation from the user before posting.
reconfigure - If a Nailgun server is being used, it is useful to be
able to reconfigure the client without restarting the nailgun
server. This scraps the current instance cached by the ng
server and creates a fresh instance.
set - Allows the user to set a configurable value on the command line.
So far, only the following configurable values are available:
terminalWidth - integer, used for calculating text wrapping.
colored - boolean, enables or disables colored output.
show - not implemented, will be used to show various information
2010-11-06 21:24:29 +00:00
|
|
|
if (!value) { // note: if option is null, value is null
|
|
|
|
println color("set", colors.option) +
|
|
|
|
color(" command requires two options: ", colors.error) +
|
2010-11-09 15:26:05 +00:00
|
|
|
"gritter set <param> <value>"
|
Added color, better nailgun support, new argument processing model, base commands.
ConsoleColor
Added to support for terminal colors by using ANSI escape codes.
Basically cross-platform (as close as we're going to get with Java's API)
TwitterCLI
Added colored output and configurable settings controlling it.
Created a specific Nailgun entry-point. When using Nailgun the Twitter
object is cached in the JVM so that it doesn't need to be recreated
each time a call is made. This also means that settings changed from the
command line persist until the Nailgun server is reset.
Added functionality to wrap the status nicely to a set width (used for
printing timelines).
Arguments are not processed internally as a Queue, so each command/option
is popped off the queue before it is processed.
Added and updated base commands:
help - not implemented, will be used to display online help about a
command.
post - Basic implementation added. It checks the length of the status,
and asks for confirmation from the user before posting.
reconfigure - If a Nailgun server is being used, it is useful to be
able to reconfigure the client without restarting the nailgun
server. This scraps the current instance cached by the ng
server and creates a fresh instance.
set - Allows the user to set a configurable value on the command line.
So far, only the following configurable values are available:
terminalWidth - integer, used for calculating text wrapping.
colored - boolean, enables or disables colored output.
show - not implemented, will be used to show various information
2010-11-06 21:24:29 +00:00
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
switch (option) {
|
|
|
|
case "terminalWidth": terminalWidth = value as int; break
|
|
|
|
case "colored": colored = value.toLowerCase() ==~ /true|t|on|yes|y/
|
|
|
|
break
|
2010-11-06 15:52:52 +00:00
|
|
|
|
|
|
|
default:
|
Added color, better nailgun support, new argument processing model, base commands.
ConsoleColor
Added to support for terminal colors by using ANSI escape codes.
Basically cross-platform (as close as we're going to get with Java's API)
TwitterCLI
Added colored output and configurable settings controlling it.
Created a specific Nailgun entry-point. When using Nailgun the Twitter
object is cached in the JVM so that it doesn't need to be recreated
each time a call is made. This also means that settings changed from the
command line persist until the Nailgun server is reset.
Added functionality to wrap the status nicely to a set width (used for
printing timelines).
Arguments are not processed internally as a Queue, so each command/option
is popped off the queue before it is processed.
Added and updated base commands:
help - not implemented, will be used to display online help about a
command.
post - Basic implementation added. It checks the length of the status,
and asks for confirmation from the user before posting.
reconfigure - If a Nailgun server is being used, it is useful to be
able to reconfigure the client without restarting the nailgun
server. This scraps the current instance cached by the ng
server and creates a fresh instance.
set - Allows the user to set a configurable value on the command line.
So far, only the following configurable values are available:
terminalWidth - integer, used for calculating text wrapping.
colored - boolean, enables or disables colored output.
show - not implemented, will be used to show various information
2010-11-06 21:24:29 +00:00
|
|
|
println color("No property named ", colors.error) +
|
|
|
|
color(option, colors.option) +
|
|
|
|
color(" exists.", colors.error)
|
2010-11-06 15:52:52 +00:00
|
|
|
}
|
Added color, better nailgun support, new argument processing model, base commands.
ConsoleColor
Added to support for terminal colors by using ANSI escape codes.
Basically cross-platform (as close as we're going to get with Java's API)
TwitterCLI
Added colored output and configurable settings controlling it.
Created a specific Nailgun entry-point. When using Nailgun the Twitter
object is cached in the JVM so that it doesn't need to be recreated
each time a call is made. This also means that settings changed from the
command line persist until the Nailgun server is reset.
Added functionality to wrap the status nicely to a set width (used for
printing timelines).
Arguments are not processed internally as a Queue, so each command/option
is popped off the queue before it is processed.
Added and updated base commands:
help - not implemented, will be used to display online help about a
command.
post - Basic implementation added. It checks the length of the status,
and asks for confirmation from the user before posting.
reconfigure - If a Nailgun server is being used, it is useful to be
able to reconfigure the client without restarting the nailgun
server. This scraps the current instance cached by the ng
server and creates a fresh instance.
set - Allows the user to set a configurable value on the command line.
So far, only the following configurable values are available:
terminalWidth - integer, used for calculating text wrapping.
colored - boolean, enables or disables colored output.
show - not implemented, will be used to show various information
2010-11-06 21:24:29 +00:00
|
|
|
}
|
|
|
|
|
2010-11-09 15:26:05 +00:00
|
|
|
public void showList(LinkedList args) {
|
|
|
|
def option = args.poll()
|
|
|
|
|
|
|
|
log.debug("Processing a 'show list' command, option = '{}'", option)
|
2010-11-06 15:52:52 +00:00
|
|
|
|
2010-11-09 15:26:05 +00:00
|
|
|
switch(option) {
|
|
|
|
case "members": showListMembers(args); break
|
|
|
|
case "subscribers": showListSubscribers(args); break
|
|
|
|
case "subscriptions": showListSubscriptions(args); break
|
|
|
|
default: args.addFirst(option)
|
|
|
|
showListTimeline(args)
|
|
|
|
}
|
2010-11-06 15:52:52 +00:00
|
|
|
}
|
|
|
|
|
2010-11-09 15:26:05 +00:00
|
|
|
public void showTimeline(LinkedList args) {
|
Added color, better nailgun support, new argument processing model, base commands.
ConsoleColor
Added to support for terminal colors by using ANSI escape codes.
Basically cross-platform (as close as we're going to get with Java's API)
TwitterCLI
Added colored output and configurable settings controlling it.
Created a specific Nailgun entry-point. When using Nailgun the Twitter
object is cached in the JVM so that it doesn't need to be recreated
each time a call is made. This also means that settings changed from the
command line persist until the Nailgun server is reset.
Added functionality to wrap the status nicely to a set width (used for
printing timelines).
Arguments are not processed internally as a Queue, so each command/option
is popped off the queue before it is processed.
Added and updated base commands:
help - not implemented, will be used to display online help about a
command.
post - Basic implementation added. It checks the length of the status,
and asks for confirmation from the user before posting.
reconfigure - If a Nailgun server is being used, it is useful to be
able to reconfigure the client without restarting the nailgun
server. This scraps the current instance cached by the ng
server and creates a fresh instance.
set - Allows the user to set a configurable value on the command line.
So far, only the following configurable values are available:
terminalWidth - integer, used for calculating text wrapping.
colored - boolean, enables or disables colored output.
show - not implemented, will be used to show various information
2010-11-06 21:24:29 +00:00
|
|
|
|
2010-11-09 15:26:05 +00:00
|
|
|
String timeline = args.poll() ?: "home"
|
Added color, better nailgun support, new argument processing model, base commands.
ConsoleColor
Added to support for terminal colors by using ANSI escape codes.
Basically cross-platform (as close as we're going to get with Java's API)
TwitterCLI
Added colored output and configurable settings controlling it.
Created a specific Nailgun entry-point. When using Nailgun the Twitter
object is cached in the JVM so that it doesn't need to be recreated
each time a call is made. This also means that settings changed from the
command line persist until the Nailgun server is reset.
Added functionality to wrap the status nicely to a set width (used for
printing timelines).
Arguments are not processed internally as a Queue, so each command/option
is popped off the queue before it is processed.
Added and updated base commands:
help - not implemented, will be used to display online help about a
command.
post - Basic implementation added. It checks the length of the status,
and asks for confirmation from the user before posting.
reconfigure - If a Nailgun server is being used, it is useful to be
able to reconfigure the client without restarting the nailgun
server. This scraps the current instance cached by the ng
server and creates a fresh instance.
set - Allows the user to set a configurable value on the command line.
So far, only the following configurable values are available:
terminalWidth - integer, used for calculating text wrapping.
colored - boolean, enables or disables colored output.
show - not implemented, will be used to show various information
2010-11-06 21:24:29 +00:00
|
|
|
|
2010-11-09 15:26:05 +00:00
|
|
|
log.debug("Processing a 'show timeline' command, timeline = '{}'",
|
|
|
|
timeline)
|
|
|
|
|
Added color, better nailgun support, new argument processing model, base commands.
ConsoleColor
Added to support for terminal colors by using ANSI escape codes.
Basically cross-platform (as close as we're going to get with Java's API)
TwitterCLI
Added colored output and configurable settings controlling it.
Created a specific Nailgun entry-point. When using Nailgun the Twitter
object is cached in the JVM so that it doesn't need to be recreated
each time a call is made. This also means that settings changed from the
command line persist until the Nailgun server is reset.
Added functionality to wrap the status nicely to a set width (used for
printing timelines).
Arguments are not processed internally as a Queue, so each command/option
is popped off the queue before it is processed.
Added and updated base commands:
help - not implemented, will be used to display online help about a
command.
post - Basic implementation added. It checks the length of the status,
and asks for confirmation from the user before posting.
reconfigure - If a Nailgun server is being used, it is useful to be
able to reconfigure the client without restarting the nailgun
server. This scraps the current instance cached by the ng
server and creates a fresh instance.
set - Allows the user to set a configurable value on the command line.
So far, only the following configurable values are available:
terminalWidth - integer, used for calculating text wrapping.
colored - boolean, enables or disables colored output.
show - not implemented, will be used to show various information
2010-11-06 21:24:29 +00:00
|
|
|
switch (timeline) {
|
|
|
|
// friends
|
2010-11-09 15:26:05 +00:00
|
|
|
case "friends": printTimeline(twitter.friendsTimeline); break
|
|
|
|
// home
|
|
|
|
case "home": printTimeline(twitter.homeTimeline); break
|
Added color, better nailgun support, new argument processing model, base commands.
ConsoleColor
Added to support for terminal colors by using ANSI escape codes.
Basically cross-platform (as close as we're going to get with Java's API)
TwitterCLI
Added colored output and configurable settings controlling it.
Created a specific Nailgun entry-point. When using Nailgun the Twitter
object is cached in the JVM so that it doesn't need to be recreated
each time a call is made. This also means that settings changed from the
command line persist until the Nailgun server is reset.
Added functionality to wrap the status nicely to a set width (used for
printing timelines).
Arguments are not processed internally as a Queue, so each command/option
is popped off the queue before it is processed.
Added and updated base commands:
help - not implemented, will be used to display online help about a
command.
post - Basic implementation added. It checks the length of the status,
and asks for confirmation from the user before posting.
reconfigure - If a Nailgun server is being used, it is useful to be
able to reconfigure the client without restarting the nailgun
server. This scraps the current instance cached by the ng
server and creates a fresh instance.
set - Allows the user to set a configurable value on the command line.
So far, only the following configurable values are available:
terminalWidth - integer, used for calculating text wrapping.
colored - boolean, enables or disables colored output.
show - not implemented, will be used to show various information
2010-11-06 21:24:29 +00:00
|
|
|
// mine
|
2010-11-09 15:26:05 +00:00
|
|
|
case "mine": printTimeline(twitter.userTimeline); break
|
|
|
|
// public
|
|
|
|
case "public": printTimeline(twitter.publicTimeline); break
|
Added color, better nailgun support, new argument processing model, base commands.
ConsoleColor
Added to support for terminal colors by using ANSI escape codes.
Basically cross-platform (as close as we're going to get with Java's API)
TwitterCLI
Added colored output and configurable settings controlling it.
Created a specific Nailgun entry-point. When using Nailgun the Twitter
object is cached in the JVM so that it doesn't need to be recreated
each time a call is made. This also means that settings changed from the
command line persist until the Nailgun server is reset.
Added functionality to wrap the status nicely to a set width (used for
printing timelines).
Arguments are not processed internally as a Queue, so each command/option
is popped off the queue before it is processed.
Added and updated base commands:
help - not implemented, will be used to display online help about a
command.
post - Basic implementation added. It checks the length of the status,
and asks for confirmation from the user before posting.
reconfigure - If a Nailgun server is being used, it is useful to be
able to reconfigure the client without restarting the nailgun
server. This scraps the current instance cached by the ng
server and creates a fresh instance.
set - Allows the user to set a configurable value on the command line.
So far, only the following configurable values are available:
terminalWidth - integer, used for calculating text wrapping.
colored - boolean, enables or disables colored output.
show - not implemented, will be used to show various information
2010-11-06 21:24:29 +00:00
|
|
|
// user
|
2010-11-09 15:26:05 +00:00
|
|
|
case "user":
|
Added color, better nailgun support, new argument processing model, base commands.
ConsoleColor
Added to support for terminal colors by using ANSI escape codes.
Basically cross-platform (as close as we're going to get with Java's API)
TwitterCLI
Added colored output and configurable settings controlling it.
Created a specific Nailgun entry-point. When using Nailgun the Twitter
object is cached in the JVM so that it doesn't need to be recreated
each time a call is made. This also means that settings changed from the
command line persist until the Nailgun server is reset.
Added functionality to wrap the status nicely to a set width (used for
printing timelines).
Arguments are not processed internally as a Queue, so each command/option
is popped off the queue before it is processed.
Added and updated base commands:
help - not implemented, will be used to display online help about a
command.
post - Basic implementation added. It checks the length of the status,
and asks for confirmation from the user before posting.
reconfigure - If a Nailgun server is being used, it is useful to be
able to reconfigure the client without restarting the nailgun
server. This scraps the current instance cached by the ng
server and creates a fresh instance.
set - Allows the user to set a configurable value on the command line.
So far, only the following configurable values are available:
terminalWidth - integer, used for calculating text wrapping.
colored - boolean, enables or disables colored output.
show - not implemented, will be used to show various information
2010-11-06 21:24:29 +00:00
|
|
|
String user = args.poll()
|
|
|
|
if (user) {
|
|
|
|
if (user.isNumber())
|
|
|
|
printTimeline(twitter.getUserTimeline(user as int))
|
|
|
|
else printTimeline(twitter.getUserTimeline(user))
|
|
|
|
} else println color("No user specified.", colors.error)
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
println color("Unknown timeline: ", colors.error) +
|
|
|
|
color(timeline, colors.option)
|
|
|
|
break;
|
2010-11-05 23:10:03 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-11-09 15:26:05 +00:00
|
|
|
public void showUser(LinkedList args) {
|
|
|
|
def user = args.poll()
|
|
|
|
|
|
|
|
log.debug("Processing a 'show user' command, user = '{}'", user)
|
|
|
|
}
|
|
|
|
|
|
|
|
public void createList(LinkedList args) {
|
|
|
|
def option = args.poll()
|
|
|
|
|
|
|
|
switch(option) {
|
|
|
|
case "member": addListMember(args); break
|
|
|
|
case "subscription": addListSubscription(args); break
|
|
|
|
default: args.addFirst(option)
|
|
|
|
createNewList(args); break
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* ======== WORKER FUNCTIONS ========*/
|
|
|
|
|
2010-11-09 22:53:44 +00:00
|
|
|
public void printLists(def lists) {
|
|
|
|
int colSize = 0
|
|
|
|
|
|
|
|
// fins largest indentation needed
|
|
|
|
lists.each { list ->
|
|
|
|
curColSize = list.user.screenName.length() +
|
|
|
|
list.user.slug.length() + list.user.fullName.length() +
|
|
|
|
list.user.id.length()
|
|
|
|
|
|
|
|
colSize = Math.max(colSize, curColSize)
|
|
|
|
}
|
|
|
|
|
|
|
|
lists.each { list ->
|
|
|
|
col1 = color(list.user.screenName, color.author) + "/" +
|
|
|
|
color("${list.slug} (${list.id})", color.option)
|
|
|
|
println col1.padLeft(colSize) + ": " + list.fullName
|
|
|
|
|
|
|
|
print color("M: ${list.user.memberCount} S: ${list.user.subscriberCount}".
|
|
|
|
padLeft(2).padRight(colSize - 2), colors.author)
|
|
|
|
|
|
|
|
println wrapToWidth(list.description, terminalWidth,
|
|
|
|
"".padLeft(colSize), "").subtring(colSize)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-11-09 15:26:05 +00:00
|
|
|
public void printTimeline(def timeline) {
|
|
|
|
|
|
|
|
log.debug("Printing a timeline: {}", timeline)
|
Added color, better nailgun support, new argument processing model, base commands.
ConsoleColor
Added to support for terminal colors by using ANSI escape codes.
Basically cross-platform (as close as we're going to get with Java's API)
TwitterCLI
Added colored output and configurable settings controlling it.
Created a specific Nailgun entry-point. When using Nailgun the Twitter
object is cached in the JVM so that it doesn't need to be recreated
each time a call is made. This also means that settings changed from the
command line persist until the Nailgun server is reset.
Added functionality to wrap the status nicely to a set width (used for
printing timelines).
Arguments are not processed internally as a Queue, so each command/option
is popped off the queue before it is processed.
Added and updated base commands:
help - not implemented, will be used to display online help about a
command.
post - Basic implementation added. It checks the length of the status,
and asks for confirmation from the user before posting.
reconfigure - If a Nailgun server is being used, it is useful to be
able to reconfigure the client without restarting the nailgun
server. This scraps the current instance cached by the ng
server and creates a fresh instance.
set - Allows the user to set a configurable value on the command line.
So far, only the following configurable values are available:
terminalWidth - integer, used for calculating text wrapping.
colored - boolean, enables or disables colored output.
show - not implemented, will be used to show various information
2010-11-06 21:24:29 +00:00
|
|
|
|
2010-11-09 15:26:05 +00:00
|
|
|
Map formatOptions = [:]
|
|
|
|
|
|
|
|
formatOptions.authorLength = 0
|
Added color, better nailgun support, new argument processing model, base commands.
ConsoleColor
Added to support for terminal colors by using ANSI escape codes.
Basically cross-platform (as close as we're going to get with Java's API)
TwitterCLI
Added colored output and configurable settings controlling it.
Created a specific Nailgun entry-point. When using Nailgun the Twitter
object is cached in the JVM so that it doesn't need to be recreated
each time a call is made. This also means that settings changed from the
command line persist until the Nailgun server is reset.
Added functionality to wrap the status nicely to a set width (used for
printing timelines).
Arguments are not processed internally as a Queue, so each command/option
is popped off the queue before it is processed.
Added and updated base commands:
help - not implemented, will be used to display online help about a
command.
post - Basic implementation added. It checks the length of the status,
and asks for confirmation from the user before posting.
reconfigure - If a Nailgun server is being used, it is useful to be
able to reconfigure the client without restarting the nailgun
server. This scraps the current instance cached by the ng
server and creates a fresh instance.
set - Allows the user to set a configurable value on the command line.
So far, only the following configurable values are available:
terminalWidth - integer, used for calculating text wrapping.
colored - boolean, enables or disables colored output.
show - not implemented, will be used to show various information
2010-11-06 21:24:29 +00:00
|
|
|
|
2010-11-05 23:10:03 +00:00
|
|
|
timeline.each { status ->
|
2010-11-09 15:26:05 +00:00
|
|
|
if (status.user.screenName.length() > formatOptions.authorLength)
|
|
|
|
formatOptions.authorLength = status.user.screenName.length()
|
Added color, better nailgun support, new argument processing model, base commands.
ConsoleColor
Added to support for terminal colors by using ANSI escape codes.
Basically cross-platform (as close as we're going to get with Java's API)
TwitterCLI
Added colored output and configurable settings controlling it.
Created a specific Nailgun entry-point. When using Nailgun the Twitter
object is cached in the JVM so that it doesn't need to be recreated
each time a call is made. This also means that settings changed from the
command line persist until the Nailgun server is reset.
Added functionality to wrap the status nicely to a set width (used for
printing timelines).
Arguments are not processed internally as a Queue, so each command/option
is popped off the queue before it is processed.
Added and updated base commands:
help - not implemented, will be used to display online help about a
command.
post - Basic implementation added. It checks the length of the status,
and asks for confirmation from the user before posting.
reconfigure - If a Nailgun server is being used, it is useful to be
able to reconfigure the client without restarting the nailgun
server. This scraps the current instance cached by the ng
server and creates a fresh instance.
set - Allows the user to set a configurable value on the command line.
So far, only the following configurable values are available:
terminalWidth - integer, used for calculating text wrapping.
colored - boolean, enables or disables colored output.
show - not implemented, will be used to show various information
2010-11-06 21:24:29 +00:00
|
|
|
}
|
|
|
|
|
2010-11-09 15:26:05 +00:00
|
|
|
formatOptions.indent = "".padLeft(formatOptions.authorLength + 2)
|
|
|
|
|
Added color, better nailgun support, new argument processing model, base commands.
ConsoleColor
Added to support for terminal colors by using ANSI escape codes.
Basically cross-platform (as close as we're going to get with Java's API)
TwitterCLI
Added colored output and configurable settings controlling it.
Created a specific Nailgun entry-point. When using Nailgun the Twitter
object is cached in the JVM so that it doesn't need to be recreated
each time a call is made. This also means that settings changed from the
command line persist until the Nailgun server is reset.
Added functionality to wrap the status nicely to a set width (used for
printing timelines).
Arguments are not processed internally as a Queue, so each command/option
is popped off the queue before it is processed.
Added and updated base commands:
help - not implemented, will be used to display online help about a
command.
post - Basic implementation added. It checks the length of the status,
and asks for confirmation from the user before posting.
reconfigure - If a Nailgun server is being used, it is useful to be
able to reconfigure the client without restarting the nailgun
server. This scraps the current instance cached by the ng
server and creates a fresh instance.
set - Allows the user to set a configurable value on the command line.
So far, only the following configurable values are available:
terminalWidth - integer, used for calculating text wrapping.
colored - boolean, enables or disables colored output.
show - not implemented, will be used to show various information
2010-11-06 21:24:29 +00:00
|
|
|
timeline.eachWithIndex { status, rowNum ->
|
2010-11-09 15:26:05 +00:00
|
|
|
formatOptions.rowNum = rowNum
|
|
|
|
println formatStatus(status, formatOptions)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public void showLists(LinkedList args) {
|
|
|
|
def user = args.poll()
|
|
|
|
|
|
|
|
log.debug("Processing a 'show lists' command, user = '{}'", user)
|
|
|
|
|
|
|
|
if (!user) user = twitter.screenName
|
|
|
|
|
2010-11-09 22:53:44 +00:00
|
|
|
printLists(twitter.getUserLists(user, -1)) // TODO paging
|
2010-11-09 15:26:05 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public void showListMembers(LinkedList args) {
|
|
|
|
def listRef = parseListReference(args)
|
|
|
|
|
|
|
|
log.debug("Processing a 'show list members' command, list = '{}'",
|
|
|
|
listRef)
|
|
|
|
|
|
|
|
if (!listRef) {
|
|
|
|
println color("show list members", colors.option) +
|
|
|
|
color(" command requires a list reference in the form of " +
|
|
|
|
"user/list: ", colors.error) +
|
|
|
|
"gritter show list members <user/list>"
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
printUserList(twitter.getUserListMembers(
|
|
|
|
listRef.username, listRef.listId, -1)) // TODO paging
|
|
|
|
}
|
|
|
|
|
|
|
|
public void showListSubscribers(LinkedList args) {
|
|
|
|
def listRef = parseListReference(args)
|
|
|
|
|
|
|
|
log.debug("Processing a 'show list subscribers' command, list = '{}'",
|
|
|
|
listRef)
|
|
|
|
|
|
|
|
if (!listRef) {
|
|
|
|
println color("show list subscribers", colors.option) +
|
|
|
|
color(" command requires a list reference in the form of " +
|
|
|
|
"user/list: ", colors.error) +
|
|
|
|
"gritter show list subscribers <user/list>"
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
printUserList(twitter.getUserListSubscribers(
|
|
|
|
listRef.username, listRef.listId, -1)) // TODO: paging
|
|
|
|
}
|
|
|
|
|
|
|
|
public void showListSubscriptions(LinkedList args) {
|
|
|
|
def user = args.poll()
|
|
|
|
|
|
|
|
log.debug("Processing a 'show list subscriptions' command, list = '{}'",
|
|
|
|
listRef)
|
|
|
|
|
|
|
|
if (!user) user = twitter.screenName
|
|
|
|
|
|
|
|
printLists(twitter.getUserListSubscriptions(user, -1)) // TODO: paging
|
|
|
|
}
|
|
|
|
|
|
|
|
public void showListTimeline(LinkedList args) {
|
|
|
|
if (args.size() < 1) {
|
|
|
|
println color("show list", colors.option) +
|
|
|
|
color(" command requires a list reference in the form of " +
|
|
|
|
"user/list: ", colors.error) +
|
|
|
|
"gritter show list <user/list>"
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
def listRef = parseListReference(args)
|
|
|
|
|
|
|
|
log.debug("Showing a list timeline, list = '{}'", listRef)
|
|
|
|
|
|
|
|
if (listRef.listId == -1) {
|
|
|
|
println color("show list", colors.option) +
|
|
|
|
color(" command requires a list reference in the form of " +
|
|
|
|
"user/list: ", colors.error) +
|
|
|
|
"gritter show list <user/list>"
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
printTimeline(twitter.getUserListStatuses(
|
|
|
|
listRef.username, listRef.listId, new Paging())) // TODO: paging
|
|
|
|
}
|
|
|
|
|
|
|
|
public void postStatus(String status) {
|
|
|
|
|
|
|
|
log.debug("Posting a status: '{}'", status)
|
|
|
|
|
|
|
|
if (!status) {
|
|
|
|
println color("post status ", colors.option) +
|
|
|
|
color("command requires one option: ", colors.error) +
|
|
|
|
"gritter post status <status>"
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
if (status.length() > 140) {
|
|
|
|
println color("Status exceeds Twitter's 140 character limit.", colors.error)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
println "Update status: '$status'? "
|
|
|
|
if (stdin.nextLine() ==~ /yes|y|true|t/) {
|
|
|
|
try {
|
|
|
|
twitter.updateStatus(status)
|
|
|
|
println "Status posted."
|
|
|
|
} catch (Exception e) {
|
|
|
|
println "An error occurred trying to post the status: '" +
|
|
|
|
e.localizedMessage
|
|
|
|
log.error("Error posting status:", e)
|
|
|
|
}
|
|
|
|
} else println "Status post canceled."
|
|
|
|
}
|
|
|
|
|
|
|
|
public void retweetStatus(def statusId) {
|
|
|
|
|
|
|
|
log.debug("Retweeting a status: '{}'", statusId)
|
|
|
|
|
|
|
|
if (!statusId.isLong() || !statusId) {
|
|
|
|
println color("retweet ", colors.option) +
|
|
|
|
color("command requires a status id: ", colors.error) +
|
|
|
|
"gritter post retweet <statusId>"
|
|
|
|
}
|
|
|
|
|
|
|
|
statusId = statusId as long
|
|
|
|
def status = twitter.showStatus(statusId)
|
|
|
|
|
|
|
|
println "Retweet '" + color(status.text, colors.odd) + "'? "
|
|
|
|
if (stdin.nextLine() ==~ /yes|y|true|t/)
|
|
|
|
twitter.retweetStatus(statusId)
|
|
|
|
}
|
|
|
|
|
|
|
|
public void addListMember(LinkedList args) {
|
|
|
|
def listRef = args.poll()
|
|
|
|
def user = args.poll()
|
|
|
|
def list
|
|
|
|
|
|
|
|
log.debug("Adding a member to a list: list='{}', user='{}'",
|
|
|
|
list, user)
|
|
|
|
|
|
|
|
if (!user) {
|
|
|
|
println color("add list member", colors.option) +
|
|
|
|
color(" requires two parameters: ", colors.error) +
|
|
|
|
"gritter add list member <list-ref> <user>"
|
|
|
|
return
|
2010-11-05 23:10:03 +00:00
|
|
|
}
|
2010-11-09 15:26:05 +00:00
|
|
|
|
|
|
|
// look up the list id if neccessary
|
|
|
|
if (listRef.isInteger()) listRef = listRef as int
|
|
|
|
else list = findListByName(twitter.screenName, listRef)
|
|
|
|
|
|
|
|
if (!list) {
|
|
|
|
println color("No list found that matches the given description: ",
|
|
|
|
colors.error) + color(listRef, colors.option)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
// look up the user id if neccessary
|
|
|
|
if (user.isLong()) user = user as long
|
|
|
|
else user = twitter.showUser(user).id
|
|
|
|
|
|
|
|
twitter.addUserListMember(list, user)
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
public void addListSubscription(LinkedList args) {
|
|
|
|
def listRef = parseListReference(args)
|
|
|
|
|
|
|
|
log.debug("Subscribing to a list: list='{}'", listRef)
|
|
|
|
|
|
|
|
if (!listRef) {
|
|
|
|
println color("add list subscription ", colors.option) +
|
|
|
|
color("expects a list name, user/list: ", colors.error) +
|
|
|
|
"gritter add list subscription <user/list>"
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
twitter.subscribeUserList(listRef.username, listRef.listId)
|
|
|
|
}
|
|
|
|
|
|
|
|
public void createNewList(LinkedList args) {
|
|
|
|
def name = args.poll()
|
|
|
|
def isPublic = args.poll()
|
|
|
|
def desc = args.poll()
|
|
|
|
|
|
|
|
log.debug("Creating a new list: name='{}', isPublic='{}', desc='{}'",
|
|
|
|
name, isPublic, desc)
|
|
|
|
|
|
|
|
if (desc == null) {
|
|
|
|
println color("create list ", colors.option) +
|
|
|
|
color("command requires three arguments: ", colors.error) +
|
|
|
|
"gritter create list <listName> <isPublic> <listDescription>"
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
println "Create list '${color(list, colors.option)}'?"
|
|
|
|
if (stdin.nextLine() ==~ /yes|y|true|t/)
|
|
|
|
twitter.createUserList(name, isPublic ==~ /yes|y|true|t/, desc)
|
|
|
|
}
|
|
|
|
|
|
|
|
public def parseListReference(LinkedList args) {
|
|
|
|
def username = args.poll()
|
|
|
|
def listId
|
|
|
|
|
|
|
|
log.debug("Looking up a list: ref = '{}'", username)
|
|
|
|
log.debug("remaining args='{}'", args)
|
|
|
|
|
|
|
|
if (!username) return false
|
|
|
|
|
|
|
|
username = username.split("/")
|
|
|
|
|
|
|
|
if (username.length != 2) {
|
|
|
|
listId = username[0]
|
|
|
|
username = twitter.screenName
|
|
|
|
} else {
|
|
|
|
listId = username[1]
|
|
|
|
username = username[0]
|
|
|
|
}
|
|
|
|
|
|
|
|
if (listId.isInteger()) listId = listId as int
|
|
|
|
else listId = findListByName(username, listId)
|
|
|
|
|
|
|
|
// TODO: err if list does not exist
|
|
|
|
|
|
|
|
return [username: username, listId: listId]
|
|
|
|
}
|
|
|
|
|
|
|
|
public int findListByName(String userName, String listName) {
|
|
|
|
|
|
|
|
def userLists
|
|
|
|
long cursor = -1
|
|
|
|
int listId = -1
|
|
|
|
|
|
|
|
while(listId == -1) {
|
|
|
|
userLists = twitter.getUserLists(userName, cursor)
|
|
|
|
userLists.each { list ->
|
|
|
|
if (listName == list.name || listName == list.slug)
|
|
|
|
listId = list.id
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!userLists.hasNext()) break
|
|
|
|
|
|
|
|
cursor = userLists.nextCursor
|
|
|
|
}
|
|
|
|
|
|
|
|
return listId
|
|
|
|
}
|
|
|
|
|
|
|
|
public String formatStatus(Status status, Map formatOptions) {
|
|
|
|
|
|
|
|
def indent = formatOptions.indent ?: ""
|
|
|
|
def authorLength = formatOptions.authorLength ?: 0
|
|
|
|
def rowNum = formatOptions.rowNum ?: 0
|
|
|
|
|
|
|
|
String result
|
|
|
|
def textColor = (rowNum % 2 == 0 ? colors.even : colors.odd)
|
|
|
|
|
|
|
|
// add author's username
|
|
|
|
result = color(status.user.screenName.padLeft(
|
2010-11-09 22:53:44 +00:00
|
|
|
authorLength) + ": ", colors.author, textColor)
|
2010-11-09 15:26:05 +00:00
|
|
|
|
|
|
|
// format the status text
|
|
|
|
String text = status.text
|
|
|
|
|
2010-11-09 22:53:44 +00:00
|
|
|
// if this status takes up more room than we have left on the line
|
2010-11-09 15:26:05 +00:00
|
|
|
if (text.length() > terminalWidth - indent.length()) {
|
2010-11-09 22:53:44 +00:00
|
|
|
// wrap text to terminal width
|
2010-11-09 15:26:05 +00:00
|
|
|
text = wrapToWidth(text, terminalWidth, indent, "").
|
|
|
|
substring(indent.length())
|
2010-11-09 22:53:44 +00:00
|
|
|
|
|
|
|
// if we are
|
2010-11-09 15:26:05 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// color @mentions in the tweet
|
|
|
|
text = text.replaceAll(/(@\w+)/, color("\$1", colors.mentioned, textColor))
|
|
|
|
|
|
|
|
result += text
|
|
|
|
|
|
|
|
return result
|
2010-11-05 23:10:03 +00:00
|
|
|
}
|
|
|
|
|
2010-11-06 15:52:52 +00:00
|
|
|
public static void printUsage() {
|
2010-11-05 23:10:03 +00:00
|
|
|
// TODO
|
|
|
|
}
|
Added color, better nailgun support, new argument processing model, base commands.
ConsoleColor
Added to support for terminal colors by using ANSI escape codes.
Basically cross-platform (as close as we're going to get with Java's API)
TwitterCLI
Added colored output and configurable settings controlling it.
Created a specific Nailgun entry-point. When using Nailgun the Twitter
object is cached in the JVM so that it doesn't need to be recreated
each time a call is made. This also means that settings changed from the
command line persist until the Nailgun server is reset.
Added functionality to wrap the status nicely to a set width (used for
printing timelines).
Arguments are not processed internally as a Queue, so each command/option
is popped off the queue before it is processed.
Added and updated base commands:
help - not implemented, will be used to display online help about a
command.
post - Basic implementation added. It checks the length of the status,
and asks for confirmation from the user before posting.
reconfigure - If a Nailgun server is being used, it is useful to be
able to reconfigure the client without restarting the nailgun
server. This scraps the current instance cached by the ng
server and creates a fresh instance.
set - Allows the user to set a configurable value on the command line.
So far, only the following configurable values are available:
terminalWidth - integer, used for calculating text wrapping.
colored - boolean, enables or disables colored output.
show - not implemented, will be used to show various information
2010-11-06 21:24:29 +00:00
|
|
|
|
|
|
|
public String resetColor() { colored ? "\u001b[m" : "" }
|
|
|
|
|
2010-11-07 04:51:44 +00:00
|
|
|
public String color(def message, ConsoleColor color,
|
|
|
|
ConsoleColor existing = null) {
|
Added color, better nailgun support, new argument processing model, base commands.
ConsoleColor
Added to support for terminal colors by using ANSI escape codes.
Basically cross-platform (as close as we're going to get with Java's API)
TwitterCLI
Added colored output and configurable settings controlling it.
Created a specific Nailgun entry-point. When using Nailgun the Twitter
object is cached in the JVM so that it doesn't need to be recreated
each time a call is made. This also means that settings changed from the
command line persist until the Nailgun server is reset.
Added functionality to wrap the status nicely to a set width (used for
printing timelines).
Arguments are not processed internally as a Queue, so each command/option
is popped off the queue before it is processed.
Added and updated base commands:
help - not implemented, will be used to display online help about a
command.
post - Basic implementation added. It checks the length of the status,
and asks for confirmation from the user before posting.
reconfigure - If a Nailgun server is being used, it is useful to be
able to reconfigure the client without restarting the nailgun
server. This scraps the current instance cached by the ng
server and creates a fresh instance.
set - Allows the user to set a configurable value on the command line.
So far, only the following configurable values are available:
terminalWidth - integer, used for calculating text wrapping.
colored - boolean, enables or disables colored output.
show - not implemented, will be used to show various information
2010-11-06 21:24:29 +00:00
|
|
|
if (!colored) return message
|
2010-11-07 04:51:44 +00:00
|
|
|
return color.toString() + message + (existing ?: resetColor())
|
Added color, better nailgun support, new argument processing model, base commands.
ConsoleColor
Added to support for terminal colors by using ANSI escape codes.
Basically cross-platform (as close as we're going to get with Java's API)
TwitterCLI
Added colored output and configurable settings controlling it.
Created a specific Nailgun entry-point. When using Nailgun the Twitter
object is cached in the JVM so that it doesn't need to be recreated
each time a call is made. This also means that settings changed from the
command line persist until the Nailgun server is reset.
Added functionality to wrap the status nicely to a set width (used for
printing timelines).
Arguments are not processed internally as a Queue, so each command/option
is popped off the queue before it is processed.
Added and updated base commands:
help - not implemented, will be used to display online help about a
command.
post - Basic implementation added. It checks the length of the status,
and asks for confirmation from the user before posting.
reconfigure - If a Nailgun server is being used, it is useful to be
able to reconfigure the client without restarting the nailgun
server. This scraps the current instance cached by the ng
server and creates a fresh instance.
set - Allows the user to set a configurable value on the command line.
So far, only the following configurable values are available:
terminalWidth - integer, used for calculating text wrapping.
colored - boolean, enables or disables colored output.
show - not implemented, will be used to show various information
2010-11-06 21:24:29 +00:00
|
|
|
}
|
|
|
|
|
2010-11-05 23:10:03 +00:00
|
|
|
}
|