Skip to content

Commit

Permalink
added commandline help screen
Browse files Browse the repository at this point in the history
Signed-off-by: Tolga Cakir <tolga@cevel.net>
  • Loading branch information
tolga9009 committed May 17, 2016
1 parent d97aa00 commit af91e38
Showing 1 changed file with 52 additions and 9 deletions.
61 changes: 52 additions & 9 deletions src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,47 @@
#include <cstdlib>
#include <iostream>
#include <string>
#include <vector>

#include <unistd.h>

#include <gchd.hpp>
#include <process.hpp>
#include <streamer.hpp>

void help(std::string program) {
std::cerr << "Usage: " << program << " [options]" << std::endl
<< std::endl
<< "Options:" << std::endl
<< " -c <color-space> Color Space settings [default: yuv]" << std::endl
<< " -d Capture to <output> instead of using FIFO" << std::endl
<< " -i <input-source> Input Source [default: hdmi]" << std::endl
<< " -o <output> Output Path [default: /tmp/gchd.ts]" << std::endl
<< " -p <pid-path> PID path [default: /var/run/gchd.pid]" << std::endl
<< " -r <resolution> Resolution of Input Source [default: 1080]" << std::endl;
}

void usage(std::string program, std::string optarg, std::string option, const std::vector<std::string> arguments) {
std::cerr << "Invalid argument '" << optarg << "' for '" << option << "'" << std::endl
<< "Valid arguments are:" << std::endl;

// print list of valid arguments
for (auto it : arguments) {
std::cerr << " - '" << it << "'" << std::endl;
}

std::cerr << "Try '" << program << " -h' for more information." << std::endl;
}

int main(int argc, char *argv[]) {
// set program name
// TODO move to Process class
std::string program(argv[0]);

if (program.empty()) {
program = "gchd";
}

// object for managing runtime information
Process process;

Expand All @@ -30,10 +63,9 @@ int main(int argc, char *argv[]) {
// handling command-line options
int opt;

// TODO show help information
while ((opt = getopt(argc, argv, ":c:di:o:p:r:")) != -1) {
while ((opt = getopt(argc, argv, ":c:dhi:o:p:r:")) != -1) {
switch (opt) {
case 'c':
case 'c': {
if (std::string(optarg) == "yuv") {
settings.setColorSpace(ColorSpace::YUV);
break;
Expand All @@ -42,11 +74,17 @@ int main(int argc, char *argv[]) {
break;
}

std::cerr << "Unknown colorspace argument.";
const std::vector<std::string> arguments = {"yuv", "rgb"};
usage(program, optarg, "-c", arguments);
return EXIT_FAILURE;
}
case 'd':
useFifo = false;
break;
case 'i':
case 'h':
help(program);
return EXIT_SUCCESS;
case 'i': {
if (std::string(optarg) == "composite") {
settings.setInputSource(InputSource::Composite);
break;
Expand All @@ -58,15 +96,17 @@ int main(int argc, char *argv[]) {
break;
}

std::cerr << "Unknown input source argument." << std::endl;
const std::vector<std::string> arguments = {"composite", "component", "hdmi"};
usage(program, optarg, "-i", arguments);
return EXIT_FAILURE;
}
case 'o':
outputPath = std::string(optarg);
break;
case 'p':
pidPath = std::string(optarg);
break;
case 'r':
case 'r': {
if (std::string(optarg) == "ntsc") {
settings.setResolution(Resolution::NTSC);
break;
Expand All @@ -81,13 +121,15 @@ int main(int argc, char *argv[]) {
break;
}

std::cerr << "Unknown resolution argument." << std::endl;
const std::vector<std::string> arguments = {"ntsc", "pal", "720", "1080"};
usage(program, optarg, "-r", arguments);
return EXIT_FAILURE;
}
case ':':
std::cerr << "Missing argument." << std::endl;
return EXIT_FAILURE;
case '?':
std::cerr << "Unrecognized option." << std::endl;
std::cerr << "Unknown option." << std::endl;
return EXIT_FAILURE;
default:
std::cerr << "Unexpected error." << std::endl;
Expand All @@ -112,6 +154,7 @@ int main(int argc, char *argv[]) {
// helper class for streaming audio and video from device
Streamer streamer(&process);

// TODO move to Streamer class. Let it decide, what to do.
if (useFifo) {
if (streamer.createFifo(outputPath)) {
return EXIT_FAILURE;
Expand Down

0 comments on commit af91e38

Please sign in to comment.