Add ability to accept stdin from URI
This commit is contained in:
parent
23f332035c
commit
25bfd0cfc7
@ -34,6 +34,8 @@ Usage: ./bin/rss-cli [-u FEED_URI] [CHANNEL FLAGS] [-i ITEM_INDEX] [ITEM FLAGS]
|
||||
Options:
|
||||
Required Options:
|
||||
[-u, --uri] URI URI of the rss stream
|
||||
Also accepts '-' to take input
|
||||
from stdin (stops once a newline is reached)
|
||||
|
||||
Channel information:
|
||||
[-t, --title] Get title of channel
|
||||
|
@ -11,7 +11,9 @@ void help(char* progName){
|
||||
std::cout << "[-i ITEM_INDEX] [ITEM FLAGS]\n";
|
||||
std::cout << "Options:\n";
|
||||
std::cout << "Required Options:\n";
|
||||
std::cout << " [-u, --uri] URI URI of the rss stream\n\n";
|
||||
std::cout << " [-u, --uri] URI URI of the rss stream\n";
|
||||
std::cout << " Also accepts '-' to take input\n";
|
||||
std::cout << " from stdin (stops once a newline is reached)\n\n";
|
||||
|
||||
std::cout << "Channel information:\n";
|
||||
std::cout << " [-t, --title] Get title of channel\n";
|
||||
|
37
src/rss.cpp
37
src/rss.cpp
@ -77,26 +77,31 @@ std::string rss::getURI() const { return _uri; }
|
||||
bool rss::update() {
|
||||
std::string result;
|
||||
|
||||
CURL *curl;
|
||||
CURLcode res;
|
||||
curl = curl_easy_init();
|
||||
if(_uri == "-"){
|
||||
std::getline(std::cin, result);
|
||||
return parse(result);
|
||||
} else {
|
||||
CURL *curl;
|
||||
CURLcode res;
|
||||
curl = curl_easy_init();
|
||||
|
||||
if(curl){
|
||||
curl_easy_setopt(curl, CURLOPT_URL, _uri.c_str());
|
||||
curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, rss_utils::write_to_string);
|
||||
curl_easy_setopt(curl, CURLOPT_WRITEDATA, &result);
|
||||
res = curl_easy_perform(curl);
|
||||
curl_easy_cleanup(curl);
|
||||
if(curl){
|
||||
curl_easy_setopt(curl, CURLOPT_URL, _uri.c_str());
|
||||
curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, rss_utils::write_to_string);
|
||||
curl_easy_setopt(curl, CURLOPT_WRITEDATA, &result);
|
||||
res = curl_easy_perform(curl);
|
||||
curl_easy_cleanup(curl);
|
||||
|
||||
if(res == CURLE_OK){
|
||||
return parse(result);
|
||||
} else {
|
||||
std::cerr << "curl_easy_perform(curl) failed: "
|
||||
<< curl_easy_strerror(res) << std::endl;
|
||||
if(res == CURLE_OK){
|
||||
return parse(result);
|
||||
} else {
|
||||
std::cerr << "curl_easy_perform(curl) failed: "
|
||||
<< curl_easy_strerror(res) << std::endl;
|
||||
}
|
||||
}
|
||||
_ok = false;
|
||||
return false;
|
||||
}
|
||||
_ok = false;
|
||||
return false;
|
||||
}
|
||||
|
||||
std::string rss::getTitle() const {
|
||||
|
Loading…
Reference in New Issue
Block a user