mirror of
https://github.com/benapetr/stikkit.git
synced 2025-04-25 20:41:20 -05:00
Added support for apikey, and reading apikey / expiry from conf
This commit is contained in:
parent
2857590603
commit
14ad63ba98
@ -30,6 +30,7 @@ string Configuration::Home = "";
|
||||
bool Configuration::NoExtras = false;
|
||||
string Configuration::Input = "";
|
||||
string Configuration::DefaultURL = "";
|
||||
string Configuration::Apikey = "";
|
||||
|
||||
void Configuration::Init()
|
||||
{
|
||||
@ -61,6 +62,36 @@ void Configuration::Init()
|
||||
Configuration::DefaultURL = line;
|
||||
}
|
||||
f.close();
|
||||
|
||||
//Apikey
|
||||
ifstream fapi;
|
||||
fapi.open(string(homedir + "/.stikkit/apikey").c_str());
|
||||
string lineapi;
|
||||
if(getline(fapi, lineapi))
|
||||
{
|
||||
Configuration::Apikey = lineapi;
|
||||
}
|
||||
fapi.close();
|
||||
|
||||
//expiry
|
||||
ifstream fexp;
|
||||
fexp.open(string(homedir + "/.stikkit/expiry").c_str());
|
||||
string lineexp;
|
||||
if(getline(fexp, lineexp))
|
||||
{
|
||||
Configuration::Expiry = lineexp;
|
||||
}
|
||||
fexp.close();
|
||||
|
||||
//author
|
||||
ifstream fauth;
|
||||
fauth.open(string(homedir + "/.stikkit/author").c_str());
|
||||
string lineauth;
|
||||
if(getline(fauth, lineauth))
|
||||
{
|
||||
Configuration::Author = lineauth;
|
||||
}
|
||||
fauth.close();
|
||||
}
|
||||
if (Configuration::Author.length() < 1)
|
||||
{
|
||||
|
@ -33,6 +33,7 @@ namespace Stikkit
|
||||
static string DefaultURL;
|
||||
static bool Private;
|
||||
static string Home;
|
||||
static string Apikey;
|
||||
static bool NoExtras;
|
||||
};
|
||||
}
|
||||
|
@ -103,6 +103,12 @@ int main(int argc, char *argv[])
|
||||
readBuffer.clear();
|
||||
string post = "text=";
|
||||
post += curl_easy_escape(curl, Stikkit::Configuration::Source.c_str(), Stikkit::Configuration::Source.length());
|
||||
if (Stikkit::Configuration::Apikey.length() > 0)
|
||||
{
|
||||
Stikkit::Configuration::URL += "?apikey=";
|
||||
Stikkit::Configuration::URL += curl_easy_escape(curl, Stikkit::Configuration::Apikey.c_str(), Stikkit::Configuration::Apikey.length());
|
||||
}
|
||||
|
||||
if (Stikkit::Configuration::Author.length() > 0)
|
||||
{
|
||||
post += "&name=";
|
||||
|
@ -95,6 +95,17 @@ bool TerminalParser::Parse()
|
||||
cerr << "Parameter -i requires an argument for it to work!" << endl;
|
||||
return true;
|
||||
}
|
||||
} else if (text.at(0) == 'k')
|
||||
{
|
||||
if (this->argc > x + 1 && !this->argv[x + 1][0] != '-')
|
||||
{
|
||||
x++;
|
||||
Configuration::Apikey = this->argv[x];
|
||||
} else
|
||||
{
|
||||
cerr << "Parameter -k requires an argument for it to work!" << endl;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
text = text.substr(1);
|
||||
}
|
||||
@ -149,6 +160,7 @@ void TerminalParser::DisplayHelp()
|
||||
" -s: Display only RAW url of paste and no extra text\n"\
|
||||
" -e <minutes>: Set expiry in minutes, parameter needs\n"\
|
||||
" to be a number, default: unlimited time\n"\
|
||||
" -k <apikey>: Set api key for current server\n"\
|
||||
" --version: Display a version\n"\
|
||||
" -h | --help: Display this help\n\n"\
|
||||
"Note: every argument in [brackets] is optional\n"\
|
||||
|
Loading…
x
Reference in New Issue
Block a user