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:
|
Options:
|
||||||
Required Options:
|
Required Options:
|
||||||
[-u, --uri] URI URI of the rss stream
|
[-u, --uri] URI URI of the rss stream
|
||||||
|
Also accepts '-' to take input
|
||||||
|
from stdin (stops once a newline is reached)
|
||||||
|
|
||||||
Channel information:
|
Channel information:
|
||||||
[-t, --title] Get title of channel
|
[-t, --title] Get title of channel
|
||||||
|
@ -11,7 +11,9 @@ void help(char* progName){
|
|||||||
std::cout << "[-i ITEM_INDEX] [ITEM FLAGS]\n";
|
std::cout << "[-i ITEM_INDEX] [ITEM FLAGS]\n";
|
||||||
std::cout << "Options:\n";
|
std::cout << "Options:\n";
|
||||||
std::cout << "Required 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 << "Channel information:\n";
|
||||||
std::cout << " [-t, --title] Get title of channel\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() {
|
bool rss::update() {
|
||||||
std::string result;
|
std::string result;
|
||||||
|
|
||||||
CURL *curl;
|
if(_uri == "-"){
|
||||||
CURLcode res;
|
std::getline(std::cin, result);
|
||||||
curl = curl_easy_init();
|
return parse(result);
|
||||||
|
} else {
|
||||||
|
CURL *curl;
|
||||||
|
CURLcode res;
|
||||||
|
curl = curl_easy_init();
|
||||||
|
|
||||||
if(curl){
|
if(curl){
|
||||||
curl_easy_setopt(curl, CURLOPT_URL, _uri.c_str());
|
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_WRITEFUNCTION, rss_utils::write_to_string);
|
||||||
curl_easy_setopt(curl, CURLOPT_WRITEDATA, &result);
|
curl_easy_setopt(curl, CURLOPT_WRITEDATA, &result);
|
||||||
res = curl_easy_perform(curl);
|
res = curl_easy_perform(curl);
|
||||||
curl_easy_cleanup(curl);
|
curl_easy_cleanup(curl);
|
||||||
|
|
||||||
if(res == CURLE_OK){
|
if(res == CURLE_OK){
|
||||||
return parse(result);
|
return parse(result);
|
||||||
} else {
|
} else {
|
||||||
std::cerr << "curl_easy_perform(curl) failed: "
|
std::cerr << "curl_easy_perform(curl) failed: "
|
||||||
<< curl_easy_strerror(res) << std::endl;
|
<< curl_easy_strerror(res) << std::endl;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
_ok = false;
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
_ok = false;
|
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string rss::getTitle() const {
|
std::string rss::getTitle() const {
|
||||||
|
Loading…
Reference in New Issue
Block a user