mirror of
https://github.com/benapetr/stikkit.git
synced 2025-04-25 20:41:20 -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";
|
||||
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()
|
||||
|
@ -8,9 +8,12 @@
|
||||
//MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
//GNU General Public License for more details.
|
||||
|
||||
#include <cstring>
|
||||
#include <iostream>
|
||||
#include <errno.h>
|
||||
#include <string>
|
||||
#include <curl/curl.h>
|
||||
#include <fstream>
|
||||
#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");
|
||||
|
@ -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 <name>: Specify author name by default the current\n"\
|
||||
" OS username is used\n"\
|
||||
" -b <url>: Specify URL of Stikked server\n"\
|
||||
" -i <file>: Upload a content of specified file\n"\
|
||||
" -v: Increases verbosity\n"\
|
||||
" -t <title>: Set a title for a paste\n"\
|
||||
" -p: Mark a paste as private (not visible in recent pastes)\n"\
|
||||
|
Loading…
x
Reference in New Issue
Block a user