// Path: src/main/java/io/dashbase/clue/ClueContext.java
// public class ClueContext {
//   protected final CommandRegistry registry = new CommandRegistry();
// 
//   private final boolean interactiveMode;
// 
//   public ClueContext(CommandRegistrar commandRegistrar, boolean interactiveMode) {
//     commandRegistrar.registerCommands(this);
//     this.interactiveMode = interactiveMode;
//   }
// 
//   public void registerCommand(ClueCommand cmd){
//     String cmdName = cmd.getName();
//     if (registry.exists(cmdName)){
//       throw new IllegalArgumentException(cmdName+" exists!");
//     }
//     registry.registerCommand(cmd);
//   }
//   
//   public boolean isReadOnlyMode() {
//     return registry.isReadonly();
//   }
// 
//   public boolean isInteractiveMode(){
//     return interactiveMode;
//   }
//   
//   public Optional<ClueCommand> getCommand(String cmd){
//     return registry.getCommand(cmd);
//   }
//   
//   public CommandRegistry getCommandRegistry(){
//     return registry;
//   }
// 
//   public void shutdown() throws Exception{
//   }
// }
// 
// Path: src/main/java/io/dashbase/clue/LuceneContext.java
// public class LuceneContext extends ClueContext {
//     private final IndexReaderFactory readerFactory;
// 
//     private IndexWriter writer;
//     private final Directory directory;
//     private final IndexWriterConfig writerConfig;
//     private final QueryBuilder queryBuilder;
//     private final AnalyzerFactory analyzerFactory;
//     private final BytesRefDisplay termBytesRefDisplay;
//     private final BytesRefDisplay payloadBytesRefDisplay;
// 
//     public LuceneContext(String dir, ClueAppConfiguration config, boolean interactiveMode)
//             throws Exception {
//         super(config.commandRegistrar, interactiveMode);
//         this.directory = config.dirBuilder.build(dir);
//         this.analyzerFactory = config.analyzerFactory;
//         this.readerFactory = config.indexReaderFactory;
//         this.readerFactory.initialize(directory);
//         this.queryBuilder = config.queryBuilder;
//         this.queryBuilder.initialize("contents", analyzerFactory.forQuery());
//         this.writerConfig = new IndexWriterConfig(new StandardAnalyzer());
//         this.termBytesRefDisplay = new StringBytesRefDisplay();
//         this.payloadBytesRefDisplay = new StringBytesRefDisplay();
//         this.writer = null;
//     }
// 
// 
//     public IndexReader getIndexReader(){
//         return readerFactory.getIndexReader();
//     }
// 
//     public IndexSearcher getIndexSearcher() {
//         return new IndexSearcher(getIndexReader());
//     }
// 
//     public IndexWriter getIndexWriter(){
//         if (registry.isReadonly()) return null;
//         if (writer == null) {
//             try {
//                 writer = new IndexWriter(directory, writerConfig);
//             } catch (IOException e) {
//                 e.printStackTrace();
//             }
//         }
//         return writer;
//     }
// 
//     Collection<String> fieldNames() {
//         LinkedList<String> fieldNames = new LinkedList<>();
//         for (LeafReaderContext context : getIndexReader().leaves()) {
//             LeafReader reader = context.reader();
//             for(FieldInfo info : reader.getFieldInfos()) {
//                 fieldNames.add(info.name);
//             }
//         }
//         return fieldNames;
//     }
// 
//     public QueryBuilder getQueryBuilder() {
//         return queryBuilder;
//     }
// 
//     public Analyzer getAnalyzerQuery() {
//         return analyzerFactory.forQuery();
//     }
// 
//     public BytesRefDisplay getTermBytesRefDisplay() {
//         return termBytesRefDisplay;
//     }
// 
//     public BytesRefDisplay getPayloadBytesRefDisplay() {
//         return payloadBytesRefDisplay;
//     }
// 
//     public Directory getDirectory() {
//         return directory;
//     }
// 
//     public void setReadOnlyMode(boolean readOnlyMode) {
//         this.registry.setReadonly(readOnlyMode);
//         if (writer != null) {
//             try {
//                 writer.close();
//             } catch (IOException e) {
//                 e.printStackTrace();
//             }
//             writer = null;
//         }
//     }
// 
//     public void refreshReader() throws Exception {
//         readerFactory.refreshReader();
//     }
// 
//     @Override
//     public void shutdown() throws Exception{
//         try {
//             readerFactory.shutdown();
//         }
//         finally{
//             directory.close();
//             if (writer != null) {
//                 writer.close();
//             }
//         }
//     }
// }


import io.dashbase.clue.ClueContext;
import io.dashbase.clue.LuceneContext;
import net.sourceforge.argparse4j.inf.ArgumentParser;
import net.sourceforge.argparse4j.inf.Namespace;
import org.apache.lucene.index.IndexWriter;
import java.io.PrintStream;
import java.util.HashMap;
import java.util.Map;
		this.ctx = ctx;
	}

	@Override
	public String getName() {
		return "savecommitdata";
	}

	@Override
	public String help() {
		return "Save user commit data";
	}

	@Override
	protected ArgumentParser buildParser(ArgumentParser parser) {
		parser.addArgument("-k", "--key").required(true);
		parser.addArgument("-v", "--value").required(true);
		return parser;
	}

	@Override
	public void execute(Namespace args, PrintStream out) throws Exception {
		IndexWriter writer = ctx.getIndexWriter();
		String key = args.getString("key");
		String val = args.getString("value");
		if (writer != null) {
			Iterable<Map.Entry<String, String>> commitData = writer.getLiveCommitData();
			HashMap<String, String> commitMap = new HashMap<>();
			if (commitData != null) {
				for (Map.Entry<String, String> entry : commitData) {
// Path: src/main/java/io/dashbase/clue/ClueContext.java
// public class ClueContext {
//   protected final CommandRegistry registry = new CommandRegistry();
// 
//   private final boolean interactiveMode;
// 
//   public ClueContext(CommandRegistrar commandRegistrar, boolean interactiveMode) {
//     commandRegistrar.registerCommands(this);
//     this.interactiveMode = interactiveMode;
//   }
// 
//   public void registerCommand(ClueCommand cmd){
//     String cmdName = cmd.getName();
//     if (registry.exists(cmdName)){
//       throw new IllegalArgumentException(cmdName+" exists!");
//     }
//     registry.registerCommand(cmd);
//   }
//   
//   public boolean isReadOnlyMode() {
//     return registry.isReadonly();
//   }
// 
//   public boolean isInteractiveMode(){
//     return interactiveMode;
//   }
//   
//   public Optional<ClueCommand> getCommand(String cmd){
//     return registry.getCommand(cmd);
//   }
//   
//   public CommandRegistry getCommandRegistry(){
//     return registry;
//   }
// 
//   public void shutdown() throws Exception{
//   }
// }
// 
// Path: src/main/java/io/dashbase/clue/LuceneContext.java
// public class LuceneContext extends ClueContext {
//     private final IndexReaderFactory readerFactory;
// 
//     private IndexWriter writer;
//     private final Directory directory;
//     private final IndexWriterConfig writerConfig;
//     private final QueryBuilder queryBuilder;
//     private final AnalyzerFactory analyzerFactory;
//     private final BytesRefDisplay termBytesRefDisplay;
//     private final BytesRefDisplay payloadBytesRefDisplay;
// 
//     public LuceneContext(String dir, ClueAppConfiguration config, boolean interactiveMode)
//             throws Exception {
//         super(config.commandRegistrar, interactiveMode);
//         this.directory = config.dirBuilder.build(dir);
//         this.analyzerFactory = config.analyzerFactory;
//         this.readerFactory = config.indexReaderFactory;
//         this.readerFactory.initialize(directory);
//         this.queryBuilder = config.queryBuilder;
//         this.queryBuilder.initialize("contents", analyzerFactory.forQuery());
//         this.writerConfig = new IndexWriterConfig(new StandardAnalyzer());
//         this.termBytesRefDisplay = new StringBytesRefDisplay();
//         this.payloadBytesRefDisplay = new StringBytesRefDisplay();
//         this.writer = null;
//     }
// 
// 
//     public IndexReader getIndexReader(){
//         return readerFactory.getIndexReader();
//     }
// 
//     public IndexSearcher getIndexSearcher() {
//         return new IndexSearcher(getIndexReader());
//     }
// 
//     public IndexWriter getIndexWriter(){
//         if (registry.isReadonly()) return null;
//         if (writer == null) {
//             try {
//                 writer = new IndexWriter(directory, writerConfig);
//             } catch (IOException e) {
//                 e.printStackTrace();
//             }
//         }
//         return writer;
//     }
// 
//     Collection<String> fieldNames() {
//         LinkedList<String> fieldNames = new LinkedList<>();
//         for (LeafReaderContext context : getIndexReader().leaves()) {
//             LeafReader reader = context.reader();
//             for(FieldInfo info : reader.getFieldInfos()) {
//                 fieldNames.add(info.name);
//             }
//         }
//         return fieldNames;
//     }
// 
//     public QueryBuilder getQueryBuilder() {
//         return queryBuilder;
//     }
// 
//     public Analyzer getAnalyzerQuery() {
//         return analyzerFactory.forQuery();
//     }
// 
//     public BytesRefDisplay getTermBytesRefDisplay() {
//         return termBytesRefDisplay;
//     }
// 
//     public BytesRefDisplay getPayloadBytesRefDisplay() {
//         return payloadBytesRefDisplay;
//     }
// 
//     public Directory getDirectory() {
//         return directory;
//     }
// 
//     public void setReadOnlyMode(boolean readOnlyMode) {
//         this.registry.setReadonly(readOnlyMode);
//         if (writer != null) {
//             try {
//                 writer.close();
//             } catch (IOException e) {
//                 e.printStackTrace();
//             }
//             writer = null;
//         }
//     }
// 
//     public void refreshReader() throws Exception {
//         readerFactory.refreshReader();
//     }
// 
//     @Override
//     public void shutdown() throws Exception{
//         try {
//             readerFactory.shutdown();
//         }
//         finally{
//             directory.close();
//             if (writer != null) {
//                 writer.close();
//             }
//         }
//     }
// }


// Path: src/main/java/io/dashbase/clue/commands/SaveUserCommitData.java
import io.dashbase.clue.ClueContext;
import io.dashbase.clue.LuceneContext;
import net.sourceforge.argparse4j.inf.ArgumentParser;
import net.sourceforge.argparse4j.inf.Namespace;
import org.apache.lucene.index.IndexWriter;
import java.io.PrintStream;
import java.util.HashMap;
import java.util.Map;

		this.ctx = ctx;
	}

	@Override
	public String getName() {
		return "savecommitdata";
	}

	@Override
	public String help() {
		return "Save user commit data";
	}

	@Override
	protected ArgumentParser buildParser(ArgumentParser parser) {
		parser.addArgument("-k", "--key").required(true);
		parser.addArgument("-v", "--value").required(true);
		return parser;
	}

	@Override
	public void execute(Namespace args, PrintStream out) throws Exception {
		IndexWriter writer = ctx.getIndexWriter();
		String key = args.getString("key");
		String val = args.getString("value");
		if (writer != null) {
			Iterable<Map.Entry<String, String>> commitData = writer.getLiveCommitData();
			HashMap<String, String> commitMap = new HashMap<>();
			if (commitData != null) {
				for (Map.Entry<String, String> entry : commitData) {
					commitMap.put(entry.getKey(), entry.getValue());