Refactored class to have a main and a nailMain.

This commit is contained in:
Jonathan Bernard 2010-11-06 10:52:52 -05:00
parent 2ff8b02025
commit ec6aed4e7f
3 changed files with 54 additions and 30 deletions

View File

@ -9,11 +9,13 @@
<target name="ng-deploy" depends="build"> <target name="ng-deploy" depends="build">
<!-- Stop the Nailgun Server --> <!-- Stop the Nailgun Server -->
<exec executable="cmd"> <exec executable="cmd" os="">
<arg value="/c"/> <arg value="/c"/>
<arg value="ng-stop"/> <arg value="ng-stop"/>
</exec> </exec>
<exec executable="ng-stop" os="Linux"/>
<!-- delete old copies --> <!-- delete old copies -->
<delete> <delete>
<fileset dir="${nailgun.classpath.dir}"> <fileset dir="${nailgun.classpath.dir}">
@ -30,9 +32,11 @@
</copy> </copy>
<!-- start the NG server up again. --> <!-- start the NG server up again. -->
<exec executable="cmd"> <exec executable="cmd" os="">
<arg value="/c"/> <arg value="/c"/>
<arg value="ng-start"/> <arg value="ng-start"/>
</exec> </exec>
<exec executable="ng-start" os="Linux"/>
</target> </target>
</project> </project>

View File

@ -1,6 +1,7 @@
#Fri, 05 Nov 2010 18:08:47 -0500 #Sat, 06 Nov 2010 10:35:28 -0500
lib.local=true lib.local=true
name=groovy-twitter-cli name=groovy-twitter-cli
version=0.1 version=0.1
build.number=14 build.number=19
nailgun.classpath.dir=C\:/Documents and Settings/jbernard/My Documents/ng-classpath nailgun.classpath.dir=/home/jdbernard/programs/nailgun/classpath
win32.nailgun.classpath.dir=C\:/Documents and Settings/jbernard/My Documents/ng-classpath

View File

@ -7,19 +7,55 @@ import twitter4j.conf.PropertyConfiguration
public class TwitterCLI { public class TwitterCLI {
static def twitter private static TwitterCLI nailgunInst
private Twitter twitter
public static void main(String[] args) { public static void main(String[] args) {
if (args.length < 1) printUsage() TwitterCLI inst = new TwitterCLI(new File(System.getProperty("user.home"),
".groovy-twitter-cli-rc"))
inst.run(args as List)
}
public static void nailMain(String[] args) {
if (nailgunInst == null) nailgunInst = new TwitterCLI(new File(
System.getProperty("user.home"), ".groovy-twitter-cli-rc"))
nailgunInst.run(args as List)
}
public static void setColor(boolean bright, int code) {
print "\u001b[${bright?'1':'0'};${code}m"
}
public static void resetColor() { print "\u001b[m" }
public static void colorPrint(def message, boolean bright, int color) {
setColor(bright, color)
print message
resetColor()
}
public static void colorPrintln(def message, boolean bright, int color) {
setColor(bright, color)
println message
resetColor()
}
public TwitterCLI(File propFile) {
// load the configuration
Configuration conf Configuration conf
File propFile = new File(System.getProperty("user.home"), ".groovy-twitter-cli-rc")
propFile.withInputStream { is -> conf = new PropertyConfiguration(is) } propFile.withInputStream { is -> conf = new PropertyConfiguration(is) }
// create a twitter instance
twitter = (new TwitterFactory(conf)).getInstance() twitter = (new TwitterFactory(conf)).getInstance()
args = args as List }
public void run(List args) {
if (args.size() < 1) printUsage()
switch (args[0].toLowerCase()) { switch (args[0].toLowerCase()) {
case ~/t.*/: timeline(args.tail()); break case ~/t.*/: timeline(args.tail()); break
@ -28,27 +64,10 @@ public class TwitterCLI {
default: default:
printUsage() printUsage()
} }
} }
void setColor(boolean bright, int code) { public void timeline(List args) {
print "\u001b[${bright?'1':'0'};${code}m"
}
void resetColor() { print "\u001b[m" }
void colorPrint(def message, boolean bright, int color) {
setColor(bright, color)
print message
resetColor()
}
void colorPrintln(def message, boolean bright, int color) {
setColor(bright, color)
println message
resetColor()
}
void timeline(List args) {
// default to showing my friends timeline // default to showing my friends timeline
if (args.size() == 0) args = ["friends"] if (args.size() == 0) args = ["friends"]
@ -83,7 +102,7 @@ public class TwitterCLI {
} }
} }
void printUsage() { public static void printUsage() {
// TODO // TODO
} }
} }