diff --git a/README.md b/README.md index af7de7b..8a25340 100644 --- a/README.md +++ b/README.md @@ -11,6 +11,18 @@ Features * Automatically url encodes all data * Automatically figure out author name if not provided explicitly +Installing on debian or ubuntu +============================== + +Just add ppa: +``` +sudo add-apt-repository ppa:benapetr/misc +sudo apt-get update +sudo apt-get install stikkit +``` + +That's all + Building on linux ================= @@ -30,10 +42,9 @@ Usage ``` stikkit -b url # now type text and hit ctrl+d to exit -``` - cat file | stikkit -b url echo "Hello world" | stikkit +``` url is an url to stikked server for example, if your server is http://something.blah/stikked and your api is http://something.blah/stikked/api then use http://something.blah/stikked as parameter to -b diff --git a/stikkit/configuration.cpp b/stikkit/configuration.cpp index eebbf5a..fd63f23 100644 --- a/stikkit/configuration.cpp +++ b/stikkit/configuration.cpp @@ -24,9 +24,10 @@ string Configuration::URL = ""; string Configuration::Expiry = "60"; bool Configuration::Private = false; string Configuration::Author = ""; -string Configuration::Version = "1.0.3"; +string Configuration::Version = "1.0.4"; string Configuration::Title = ""; string Configuration::Home = ""; +string Configuration::Input = ""; string Configuration::DefaultURL = ""; void Configuration::Init() diff --git a/stikkit/main.cpp b/stikkit/main.cpp index 1382e76..45629bc 100644 --- a/stikkit/main.cpp +++ b/stikkit/main.cpp @@ -8,9 +8,12 @@ //MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the //GNU General Public License for more details. +#include #include +#include #include #include +#include #include "configuration.hpp" #include "terminalparser.hpp" #include "syslog.hpp" @@ -70,8 +73,23 @@ int main(int argc, char *argv[]) } Stikkit::Configuration::URL += "/api/create"; std::string line; - while (getline(std::cin, line)) - Stikkit::Configuration::Source += line + "\n"; + if (Stikkit::Configuration::Input.length()) + { + // user wants to upload some file + std::ifstream infile(Stikkit::Configuration::Input.c_str()); + if (!infile) + { + cerr << "File could not be opened!" << endl; + cerr << "Error code: " << strerror(errno) << endl; + return 61; + } + while (std::getline(infile, line)) + Stikkit::Configuration::Source += line + "\n"; + } else + { + while (getline(std::cin, line)) + Stikkit::Configuration::Source += line + "\n"; + } if (Stikkit::Configuration::Source.size() < 1) { Stikkit::Syslog::Log("Refusing to upload empty string"); diff --git a/stikkit/terminalparser.cpp b/stikkit/terminalparser.cpp index 224a84f..a586c8d 100644 --- a/stikkit/terminalparser.cpp +++ b/stikkit/terminalparser.cpp @@ -70,7 +70,7 @@ bool TerminalParser::Parse() Configuration::Title = this->argv[x]; } else { - cerr << "Parameter -b requires an argument for it to work!" << endl; + cerr << "Parameter -t requires an argument for it to work!" << endl; return true; } } else if (text.at(0) == 'e') @@ -81,11 +81,21 @@ bool TerminalParser::Parse() Configuration::Expiry = this->argv[x]; } else { - cerr << "Parameter -b requires an argument for it to work!" << endl; + cerr << "Parameter -e requires an argument for it to work!" << endl; + return true; + } + } else if (text.at(0) == 'i') + { + if (this->argc > x + 1 && !this->argv[x + 1][0] != '-') + { + x++; + Configuration::Input = this->argv[x]; + } else + { + cerr << "Parameter -i requires an argument for it to work!" << endl; return true; } } - text = text.substr(1); } valid = true; @@ -135,6 +145,7 @@ void TerminalParser::DisplayHelp() " -a : Specify author name by default the current\n"\ " OS username is used\n"\ " -b : Specify URL of Stikked server\n"\ + " -i : Upload a content of specified file\n"\ " -v: Increases verbosity\n"\ " -t : Set a title for a paste\n"\ " -p: Mark a paste as private (not visible in recent pastes)\n"\