package com.tmitim.twittercli.commands;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

import org.apache.commons.lang3.StringUtils;

import com.github.rvesse.airline.annotations.Arguments;
import com.github.rvesse.airline.annotations.Command;
import com.tmitim.twittercli.Printer;

import twitter4j.Query;
import twitter4j.Status;
import twitter4j.Twitter;
import twitter4j.TwitterException;
import twitter4j.TwitterFactory;

/**
 * Tweet to twitter
 *
 */
@Command(name = "search", description = "Search twitter")
public class Search implements Runnable {

	@Arguments(description = "Additional arguments")
	private List<String> args;

	@Override
	public void run() {
		String query = StringUtils.join(args, " ");


		Twitter twitter = TwitterFactory.getSingleton();

		List<Status> statuses = new ArrayList<>();
		try {

			System.out.println("Searching for: " + query);
			if (query != null && !query.isEmpty()) {
				statuses = twitter.search(new Query(query)).getTweets();
			}

		} catch (TwitterException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}

		Collections.reverse(statuses);
		new Printer().printStatuses(statuses);
	}
}
@@ -272,16 +272,69 @@
 ommand;%0A
+import com.github.rvesse.airline.annotations.Option;%0A
 import c
@@ -671,57 +671,391 @@
  = %22
-Additional arguments%22)%0A%09private List%3CString%3E args
+Search terms%22)%0A%09private List%3CString%3E args;%0A%0A%09@Option(name = %7B %22-r%22, %22--recent%22 %7D, description = %22Search recent tweets%22)%0A%09private boolean searchRecent;%0A%0A%09@Option(name = %7B %22-p%22, %22--popular%22 %7D, description = %22Search popular tweets%22)%0A%09private boolean searchPopular;%0A%0A%09@Option(name = %7B %22-m%22, %22--mixed%22 %7D, description = %22Search a mix of recent/popular tweets%22)%0A%09private boolean searchMixed
 ;%0A%0A%09
@@ -1099,16 +1099,22 @@
 ng query
+String
  = Strin
@@ -1138,17 +1138,16 @@
  %22 %22);%0A%0A
-%0A
 %09%09Twitte
@@ -1291,16 +1291,22 @@
  + query
+String
 );%0A%09%09%09if
@@ -1312,16 +1312,22 @@
 f (query
+String
  != null
@@ -1336,16 +1336,22 @@
 & !query
+String
 .isEmpty
@@ -1360,16 +1360,444 @@
 ) %7B%0A%09%09%09%09
+Query query = new Query(queryString);%0A%09%09%09%09if (searchRecent) %7B%0A%09%09%09%09%09query.setResultType(Query.RECENT);%0A%09%09%09%09%7D%0A%0A%09%09%09%09if (searchPopular) %7B%0A%09%09%09%09%09query.setResultType(Query.POPULAR);%0A%09%09%09%09%7D%0A%0A%09%09%09%09if ((searchPopular && searchRecent) %7C%7C searchMixed) %7B%0A%09%09%09%09%09query.setResultType(Query.MIXED);%0A%09%09%09%09%7D%0A%0A%09%09%09%09System.out.println(%0A%09%09%09%09%09%09%22Searching %22 + (query.getResultType() == null ? Query.MIXED : query.getResultType())%0A%09%09%09%09%09%09%09%09+ %22 results%22);%0A%09%09%09%09
 statuses
@@ -1817,26 +1817,15 @@
 arch
-(new Query
 (query)
-)
 .get

Add search flags for popular, recent, mixed searches