Added support for -l <lang> and /etc/stikkit/apikey

This commit is contained in:
John R. Dennison 2017-03-09 04:56:56 -06:00 committed by Petr Bena
parent dcba663d8d
commit efbdaa0c6d
4 changed files with 41 additions and 0 deletions

View File

@ -31,6 +31,7 @@ bool Configuration::NoExtras = false;
string Configuration::Input = ""; string Configuration::Input = "";
string Configuration::DefaultURL = ""; string Configuration::DefaultURL = "";
string Configuration::Apikey = ""; string Configuration::Apikey = "";
string Configuration::Lang = "";
void Configuration::Init() void Configuration::Init()
{ {
@ -49,6 +50,17 @@ void Configuration::Init()
} }
f.close(); f.close();
} }
if (stat("/etc/stikkit/apikey", &st) != -1)
{
ifstream f;
f.open("/etc/stikkit/apikey");
string line;
if (getline(f, line))
{
Configuration::Apikey = line;
}
f.close();
}
if (stat(string(homedir + "/.stikkit").c_str(), &st) == -1) if (stat(string(homedir + "/.stikkit").c_str(), &st) == -1)
{ {
mkdir(string(homedir + "/.stikkit").c_str(), 0750); mkdir(string(homedir + "/.stikkit").c_str(), 0750);
@ -73,6 +85,16 @@ void Configuration::Init()
} }
fapi.close(); fapi.close();
//Lang
ifstream flang;
flang.open(string(homedir + "/.stikkit/lang").c_str());
string linelang;
if(getline(flang, linelang))
{
Configuration::Lang = linelang;
}
flang.close();
//expiry //expiry
ifstream fexp; ifstream fexp;
fexp.open(string(homedir + "/.stikkit/expiry").c_str()); fexp.open(string(homedir + "/.stikkit/expiry").c_str());

View File

@ -34,6 +34,7 @@ namespace Stikkit
static bool Private; static bool Private;
static string Home; static string Home;
static string Apikey; static string Apikey;
static string Lang;
static bool NoExtras; static bool NoExtras;
}; };
} }

View File

@ -109,6 +109,12 @@ int main(int argc, char *argv[])
Stikkit::Configuration::URL += curl_easy_escape(curl, Stikkit::Configuration::Apikey.c_str(), Stikkit::Configuration::Apikey.length()); Stikkit::Configuration::URL += curl_easy_escape(curl, Stikkit::Configuration::Apikey.c_str(), Stikkit::Configuration::Apikey.length());
} }
if (Stikkit::Configuration::Lang.length() > 0)
{
post += "&lang=";
post += curl_easy_escape(curl, Stikkit::Configuration::Lang.c_str(), Stikkit::Configuration::Lang.length());
}
if (Stikkit::Configuration::Author.length() > 0) if (Stikkit::Configuration::Author.length() > 0)
{ {
post += "&name="; post += "&name=";

View File

@ -106,6 +106,17 @@ bool TerminalParser::Parse()
cerr << "Parameter -k requires an argument for it to work!" << endl; cerr << "Parameter -k requires an argument for it to work!" << endl;
return true; return true;
} }
} else if (text.at(0) == 'l')
{
if (this->argc > x + 1 && !this->argv[x + 1][0] != '-')
{
x++;
Configuration::Lang = this->argv[x];
} else
{
cerr << "Parameter -l requires an argument for it to work!" << endl;
return true;
}
} }
text = text.substr(1); text = text.substr(1);
} }
@ -161,6 +172,7 @@ void TerminalParser::DisplayHelp()
" -e <minutes>: Set expiry in minutes, parameter needs\n"\ " -e <minutes>: Set expiry in minutes, parameter needs\n"\
" to be a number, default: unlimited time\n"\ " to be a number, default: unlimited time\n"\
" -k <apikey>: Set api key for current server\n"\ " -k <apikey>: Set api key for current server\n"\
" -l <lang>: Set paste lang for syntax highlighting\n"\
" --version: Display a version\n"\ " --version: Display a version\n"\
" -h | --help: Display this help\n\n"\ " -h | --help: Display this help\n\n"\
"Note: every argument in [brackets] is optional\n"\ "Note: every argument in [brackets] is optional\n"\