mirror of
https://github.com/benapetr/stikkit.git
synced 2025-04-26 21:11:15 -05:00
some sanity checks
This commit is contained in:
parent
8eab5b610b
commit
7973d5f6f7
@ -24,9 +24,10 @@ string Configuration::URL = "";
|
|||||||
string Configuration::Expiry = "60";
|
string Configuration::Expiry = "60";
|
||||||
bool Configuration::Private = false;
|
bool Configuration::Private = false;
|
||||||
string Configuration::Author = "";
|
string Configuration::Author = "";
|
||||||
string Configuration::Version = "1.0.3";
|
string Configuration::Version = "1.0.4";
|
||||||
string Configuration::Title = "";
|
string Configuration::Title = "";
|
||||||
string Configuration::Home = "";
|
string Configuration::Home = "";
|
||||||
|
string Configuration::Input = "";
|
||||||
string Configuration::DefaultURL = "";
|
string Configuration::DefaultURL = "";
|
||||||
|
|
||||||
void Configuration::Init()
|
void Configuration::Init()
|
||||||
|
@ -8,9 +8,12 @@
|
|||||||
//MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
//MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
//GNU General Public License for more details.
|
//GNU General Public License for more details.
|
||||||
|
|
||||||
|
#include <cstring>
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
|
#include <errno.h>
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <curl/curl.h>
|
#include <curl/curl.h>
|
||||||
|
#include <fstream>
|
||||||
#include "configuration.hpp"
|
#include "configuration.hpp"
|
||||||
#include "terminalparser.hpp"
|
#include "terminalparser.hpp"
|
||||||
#include "syslog.hpp"
|
#include "syslog.hpp"
|
||||||
@ -70,8 +73,23 @@ int main(int argc, char *argv[])
|
|||||||
}
|
}
|
||||||
Stikkit::Configuration::URL += "/api/create";
|
Stikkit::Configuration::URL += "/api/create";
|
||||||
std::string line;
|
std::string line;
|
||||||
|
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))
|
while (getline(std::cin, line))
|
||||||
Stikkit::Configuration::Source += line + "\n";
|
Stikkit::Configuration::Source += line + "\n";
|
||||||
|
}
|
||||||
if (Stikkit::Configuration::Source.size() < 1)
|
if (Stikkit::Configuration::Source.size() < 1)
|
||||||
{
|
{
|
||||||
Stikkit::Syslog::Log("Refusing to upload empty string");
|
Stikkit::Syslog::Log("Refusing to upload empty string");
|
||||||
|
@ -70,7 +70,7 @@ bool TerminalParser::Parse()
|
|||||||
Configuration::Title = this->argv[x];
|
Configuration::Title = this->argv[x];
|
||||||
} else
|
} 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;
|
return true;
|
||||||
}
|
}
|
||||||
} else if (text.at(0) == 'e')
|
} else if (text.at(0) == 'e')
|
||||||
@ -81,11 +81,21 @@ bool TerminalParser::Parse()
|
|||||||
Configuration::Expiry = this->argv[x];
|
Configuration::Expiry = this->argv[x];
|
||||||
} else
|
} 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;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
text = text.substr(1);
|
text = text.substr(1);
|
||||||
}
|
}
|
||||||
valid = true;
|
valid = true;
|
||||||
@ -135,6 +145,7 @@ void TerminalParser::DisplayHelp()
|
|||||||
" -a <name>: Specify author name by default the current\n"\
|
" -a <name>: Specify author name by default the current\n"\
|
||||||
" OS username is used\n"\
|
" OS username is used\n"\
|
||||||
" -b <url>: Specify URL of Stikked server\n"\
|
" -b <url>: Specify URL of Stikked server\n"\
|
||||||
|
" -i <file>: Upload a content of specified file\n"\
|
||||||
" -v: Increases verbosity\n"\
|
" -v: Increases verbosity\n"\
|
||||||
" -t <title>: Set a title for a paste\n"\
|
" -t <title>: Set a title for a paste\n"\
|
||||||
" -p: Mark a paste as private (not visible in recent pastes)\n"\
|
" -p: Mark a paste as private (not visible in recent pastes)\n"\
|
||||||
|
Loading…
x
Reference in New Issue
Block a user