Skip to content
GitLab
Menu
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
dcdb
dcdb
Commits
75cd26c3
Commit
75cd26c3
authored
Apr 14, 2016
by
Michael Ott
Browse files
Add proper command line parsing
parent
4ea9e9b7
Changes
1
Hide whitespace changes
Inline
Side-by-side
DCDBCSVImport/dcdbcsvimport.cpp
View file @
75cd26c3
...
...
@@ -32,15 +32,46 @@ typedef struct {
std
::
string
publicName
;
}
sensor_t
;
void
usage
(
int
argc
,
char
*
argv
[])
{
std
::
cout
<<
"Usage: "
<<
argv
[
0
]
<<
" [-h <host>] <CSV File> <SensorPrefix>"
<<
std
::
endl
<<
std
::
endl
;
std
::
cout
<<
" -h <host> - Database hostname"
<<
std
::
endl
;
std
::
cout
<<
" CSV File - CSV file with sensor readings. First row has to contain sensor names"
<<
std
::
endl
;
std
::
cout
<<
" SensorPrefix - Prefix to use for sensor names"
<<
std
::
endl
;
}
int
main
(
int
argc
,
char
**
argv
)
{
/* Check command line parameters */
if
(
argc
<
3
)
{
usage
(
argc
,
argv
);
exit
(
EXIT_FAILURE
);
}
int
ret
;
const
char
*
host
=
getenv
(
"DCDB_HOSTNAME"
);
if
(
!
host
)
{
host
=
"localhost"
;
}
while
((
ret
=
getopt
(
argc
,
argv
,
"+h:"
))
!=-
1
)
{
switch
(
ret
)
{
case
'h'
:
host
=
optarg
;
break
;
default:
usage
(
argc
,
argv
);
exit
(
EXIT_FAILURE
);
}
}
/* Connect to the data store */
std
::
cout
<<
std
::
endl
;
std
::
cout
<<
"Connecting to the data store..."
<<
std
::
endl
;
DCDB
::
Connection
*
connection
;
connection
=
new
DCDB
::
Connection
();
connection
->
setHostname
(
"127.0.0.1"
);
connection
->
setHostname
(
host
);
if
(
!
connection
->
connect
())
{
std
::
cout
<<
"Cannot connect to database."
<<
std
::
endl
;
return
1
;
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment