Skip to content

Commit e0b0beb

Browse files
committed
Merge pull request #540 from RyanGordon/cli_version
Adding in CLI -help and -version options
2 parents 3758042 + ad3f2b1 commit e0b0beb

File tree

2 files changed

+26
-12
lines changed

2 files changed

+26
-12
lines changed

examples/Protonect.cpp

Lines changed: 23 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -110,8 +110,9 @@ int main(int argc, char *argv[])
110110
/// [main]
111111
{
112112
std::string program_path(argv[0]);
113+
std::cerr << "Version: " << LIBFREENECT2_VERSION << std::endl;
113114
std::cerr << "Environment variables: LOGFILE=<protonect.log>" << std::endl;
114-
std::cerr << "Usage: " << program_path << " [gl | cl | cpu] [<device serial>] [-noviewer]" << std::endl;
115+
std::cerr << "Usage: " << program_path << " [gl | cl | cpu] [<device serial>] [-noviewer] [-help] [-version]" << std::endl;
115116
std::cerr << "To pause and unpause: pkill -USR1 Protonect" << std::endl;
116117
size_t executable_name_idx = program_path.rfind("Protonect");
117118

@@ -145,23 +146,20 @@ int main(int argc, char *argv[])
145146
libfreenect2::PacketPipeline *pipeline = 0;
146147
/// [context]
147148

148-
/// [discovery]
149-
if(freenect2.enumerateDevices() == 0)
150-
{
151-
std::cout << "no device connected!" << std::endl;
152-
return -1;
153-
}
154-
155-
std::string serial = freenect2.getDefaultDeviceSerialNumber();
156-
/// [discovery]
149+
std::string serial = "";
157150

158151
bool viewer_enabled = true;
159152

160153
for(int argI = 1; argI < argc; ++argI)
161154
{
162155
const std::string arg(argv[argI]);
163156

164-
if(arg == "cpu")
157+
if(arg == "-help" || arg == "--help" || arg == "-h" || arg == "-v" || arg == "--version" || arg == "-version")
158+
{
159+
// Just let the initial lines display at the beginning of main
160+
return 0;
161+
}
162+
else if(arg == "cpu")
165163
{
166164
if(!pipeline)
167165
/// [pipeline]
@@ -190,7 +188,7 @@ int main(int argc, char *argv[])
190188
{
191189
serial = arg;
192190
}
193-
else if(arg == "-noviewer")
191+
else if(arg == "-noviewer" || arg == "--noviewer")
194192
{
195193
viewer_enabled = false;
196194
}
@@ -200,6 +198,19 @@ int main(int argc, char *argv[])
200198
}
201199
}
202200

201+
/// [discovery]
202+
if(freenect2.enumerateDevices() == 0)
203+
{
204+
std::cout << "no device connected!" << std::endl;
205+
return -1;
206+
}
207+
208+
if (serial == "")
209+
{
210+
serial = freenect2.getDefaultDeviceSerialNumber();
211+
}
212+
/// [discovery]
213+
203214
if(pipeline)
204215
{
205216
/// [open]

include/libfreenect2/config.h.in

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,9 @@
2727
#ifndef LIBFREENECT2_CONFIG_H
2828
#define LIBFREENECT2_CONFIG_H
2929

30+
#define LIBFREENECT2_VERSION "@PROJECT_VER@"
31+
#define LIBFREENECT2_API_VERSION ((@PROJECT_VER_MAJOR@ << 16) | @PROJECT_VER_MINOR@)
32+
3033
#ifdef _MSC_VER
3134
#define LIBFREENECT2_PACK( __Declaration__ ) __pragma( pack(push, 1) ) __Declaration__ __pragma( pack(pop) )
3235
#else

0 commit comments

Comments
 (0)