From e006e066853705723a53834888daa68976904729 Mon Sep 17 00:00:00 2001
From: Starbeamrainbowlabs <sbrl@starbeamrainbowlabs.com>
Date: Wed, 26 Sep 2018 20:50:16 +0100
Subject: [PATCH] Refactor help text to a separate file

---
 SearchBox-CLI/EmbeddedFiles/Help.txt | 34 ++++++++++++++++++++++++++++
 SearchBox-CLI/Program.cs             | 34 ++--------------------------
 SearchBox-CLI/SearchBox-CLI.csproj   | 10 +++++++-
 3 files changed, 45 insertions(+), 33 deletions(-)
 create mode 100644 SearchBox-CLI/EmbeddedFiles/Help.txt

diff --git a/SearchBox-CLI/EmbeddedFiles/Help.txt b/SearchBox-CLI/EmbeddedFiles/Help.txt
new file mode 100644
index 0000000..0fa5dca
--- /dev/null
+++ b/SearchBox-CLI/EmbeddedFiles/Help.txt
@@ -0,0 +1,34 @@
+SearchBox
+---------
+A standalone full-text search engine. Operates on plain text sources.
+
+Usage:
+	./SearchBox.exe {mode} [options]
+
+Modes:
+	query     Query a pre-existing inverted search index
+	context   Generate a context string similar to a search result on the internet
+	index     Generate a raw index of the source document.
+	add       Add a named document to a search index.
+	remove    Remove a named document from a search index.
+	update    Update a named document in a search index.
+
+Options:
+	--batch         Enters a mode where the operations to process are specified  the source (by default stdin; change with --source as usual) - one per line in the format "{filename}|{name}|{tags}" {add}
+	--format        Sets the format of the output. Possible values: text (defaul json, html (context generation only) {query, index, context}
+	--index         Specifies the location of the search index to use {add, remo update}
+	--name, -n      Sets the name of the source document {add, remove, title}
+	--new-source    Specifies the path to the new version of the source document update {update}
+	--limit         Limits the number of results returned, -1 = no limit {query}
+	--offset        Skips the specified number of results from the beginning of  results list {query}
+	--old-source    Specifies the path to the old version of the source document update {update}
+	--query         Specifies the query string {query, context}
+	--source, -s    Specifies the path to the source document {index, add,context}
+	--tags          Sets the tags to associate with the document. {add, update}
+
+Examples:
+	Add a file to an index:
+		./SearchBox.exe add --name "Complex Knots: How do and undo them" <books/complex_knots.txt
+	
+	Add multiple files to an index in batch mode:
+		time find sources/ -type f -print0 | xargs -0 -n1 -I{} sh -c 'echo {}\|$(basename -s .md "{}")\|' | ./lib/SearchBox/SearchBox-CLI.exe add --batch --index data/posts.sindex
diff --git a/SearchBox-CLI/Program.cs b/SearchBox-CLI/Program.cs
index 810c606..d2d7045 100644
--- a/SearchBox-CLI/Program.cs
+++ b/SearchBox-CLI/Program.cs
@@ -132,37 +132,7 @@ namespace SearchBoxCLI
 
 		private static int HandleHelp()
 		{
-			Console.WriteLine("SearchBox");
-			Console.WriteLine("---------");
-			Console.WriteLine("A standalone full-text search engine. Operates on plain text sources.");
-			Console.WriteLine();
-			Console.WriteLine("Usage:");
-			Console.WriteLine("    ./SearchBox.exe {mode} [options]");
-			Console.WriteLine();
-			Console.WriteLine("Modes:");
-			Console.WriteLine("    query     Query a pre-existing inverted search index");
-			Console.WriteLine("    context   Generate a context string similar to a search result on the internet");
-			Console.WriteLine("    index     Generate a raw index of the source document.");
-			Console.WriteLine("    add       Add a named document to a search index.");
-			Console.WriteLine("    remove    Remove a named document from a search index.");
-			Console.WriteLine("    update    Update a named document in a search index.");
-			Console.WriteLine();
-			Console.WriteLine("Options:");
-			Console.WriteLine("    --batch         Enters a mode where the operations to process are specified via the source (by default stdin; change with --source as usual) - one per line in the format \"{filename}|{name}|{tags}\" {add}");
-			Console.WriteLine("    --format        Sets the format of the output. Possible values: text (default), json, html (context generation only) {query, index, context}");
-			Console.WriteLine("    --index         Specifies the location of the search index to use {add, remove, update}");
-			Console.WriteLine("    --name, -n      Sets the name of the source document {add, remove, title}");
-			Console.WriteLine("    --new-source    Specifies the path to the new version of the source document to update {update}");
-			Console.WriteLine("    --limit         Limits the number of results returned, -1 = no limit {query}");
-			Console.WriteLine("    --offset        Skips the specified number of results from the beginning of the results list {query}");
-			Console.WriteLine("    --old-source    Specifies the path to the old version of the source document to update {update}");
-			Console.WriteLine("    --query         Specifies the query string {query, context}");
-			Console.WriteLine("    --source, -s    Specifies the path to the source document {index, add,context}");
-			Console.WriteLine("    --tags          Sets the tags to associate with the document. {add, update}");
-			Console.WriteLine();
-			Console.WriteLine("Examples:");
-			Console.WriteLine("    cat books/complex_knots.txt | ./SearchBox.exe add --name \"Complex Knots: How to do and undo them\"");
-			Console.WriteLine();
+			Console.WriteLine(EmbeddedFiles.ReadAllText("SearchBoxCLI.EmbeddedFiles.Help.txt"));
 			return 1;
 		}
 
@@ -211,7 +181,7 @@ namespace SearchBoxCLI
 
 			File.WriteAllText(SearchIndexFilepath, JsonConvert.SerializeObject(searchBox));
 
-			Console.Error.WriteLine($"[Searchbox] [add] {Name} -> {SearchIndexFilepath}");
+			Console.Error.WriteLine($"[Searchbox] [save] {Name} -> {SearchIndexFilepath}");
 
 			return 0;
 		}
diff --git a/SearchBox-CLI/SearchBox-CLI.csproj b/SearchBox-CLI/SearchBox-CLI.csproj
index 110dd92..978c4a9 100644
--- a/SearchBox-CLI/SearchBox-CLI.csproj
+++ b/SearchBox-CLI/SearchBox-CLI.csproj
@@ -54,5 +54,13 @@
   <ItemGroup>
     <Folder Include="Utilities\" />
   </ItemGroup>
+  
+  <ItemGroup>
+    <EmbeddedResource Include="EmbeddedFiles\Help.txt" />
+  </ItemGroup>
+  <Target Name="AfterBuild">
+  	<Exec Command="chmod -x *" WorkingDirectory="$(OutDir)" />
+  	<Exec Command="chmod +x *.exe" WorkingDirectory="$(OutDir)" />
+  </Target>
   <Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
-</Project>
\ No newline at end of file
+</Project>
