Skip to content

Commit

Permalink
Refactoring of arg and config get procedures.
Browse files Browse the repository at this point in the history
  • Loading branch information
interkosmos committed Sep 15, 2024
1 parent 10e7c82 commit 42231f8
Show file tree
Hide file tree
Showing 26 changed files with 527 additions and 496 deletions.
10 changes: 5 additions & 5 deletions app/dmbackup.f90
Original file line number Diff line number Diff line change
Expand Up @@ -96,11 +96,11 @@ integer function read_args(app) result(rc)
rc = dm_arg_read(args, APP_NAME, APP_MAJOR, APP_MINOR, APP_PATCH, dm_db_version(.true.))
if (dm_is_error(rc)) return

rc = dm_arg_get(args(1), app%database)
rc = dm_arg_get(args(2), app%backup)
rc = dm_arg_get(args(3), app%vacuum)
rc = dm_arg_get(args(4), app%wal)
rc = dm_arg_get(args(5), app%verbose)
call dm_arg_get(args(1), app%database)
call dm_arg_get(args(2), app%backup)
call dm_arg_get(args(3), app%vacuum)
call dm_arg_get(args(4), app%wal)
call dm_arg_get(args(5), app%verbose)

rc = E_INVALID

Expand Down
49 changes: 24 additions & 25 deletions app/dmbeat.f90
Original file line number Diff line number Diff line change
Expand Up @@ -101,25 +101,25 @@ integer function read_args(app) result(rc)
rc = dm_arg_read(args, APP_NAME, APP_MAJOR, APP_MINOR, APP_PATCH, version)
if (dm_is_error(rc)) return

rc = dm_arg_get(args(1), app%name)
rc = dm_arg_get(args(2), app%config)
call dm_arg_get(args(1), app%name)
call dm_arg_get(args(2), app%config)

! Read configuration from file.
rc = read_config(app)
if (dm_is_error(rc)) return

! Get all other arguments.
rc = dm_arg_get(args( 3), app%logger)
rc = dm_arg_get(args( 4), app%node)
rc = dm_arg_get(args( 5), app%host)
rc = dm_arg_get(args( 6), app%port)
rc = dm_arg_get(args( 7), app%tls)
rc = dm_arg_get(args( 8), app%username)
rc = dm_arg_get(args( 9), app%password)
rc = dm_arg_get(args(10), app%count)
rc = dm_arg_get(args(11), app%interval)
rc = dm_arg_get(args(12), app%debug)
rc = dm_arg_get(args(13), app%verbose)
call dm_arg_get(args( 3), app%logger)
call dm_arg_get(args( 4), app%node)
call dm_arg_get(args( 5), app%host)
call dm_arg_get(args( 6), app%port)
call dm_arg_get(args( 7), app%tls)
call dm_arg_get(args( 8), app%username)
call dm_arg_get(args( 9), app%password)
call dm_arg_get(args(10), app%count)
call dm_arg_get(args(11), app%interval)
call dm_arg_get(args(12), app%debug)
call dm_arg_get(args(13), app%verbose)

rc = E_INVALID

Expand Down Expand Up @@ -166,18 +166,17 @@ integer function read_config(app) result(rc)
rc = dm_config_open(config, app%config, app%name)

if (dm_is_ok(rc)) then
rc = dm_config_get(config, 'logger', app%logger)
rc = dm_config_get(config, 'node', app%node)
rc = dm_config_get(config, 'host', app%host)
rc = dm_config_get(config, 'port', app%port)
rc = dm_config_get(config, 'tls', app%tls)
rc = dm_config_get(config, 'username', app%username)
rc = dm_config_get(config, 'password', app%password)
rc = dm_config_get(config, 'count', app%count)
rc = dm_config_get(config, 'interval', app%interval)
rc = dm_config_get(config, 'debug', app%debug)
rc = dm_config_get(config, 'verbose', app%verbose)
rc = E_NONE
call dm_config_get(config, 'logger', app%logger)
call dm_config_get(config, 'node', app%node)
call dm_config_get(config, 'host', app%host)
call dm_config_get(config, 'port', app%port)
call dm_config_get(config, 'tls', app%tls)
call dm_config_get(config, 'username', app%username)
call dm_config_get(config, 'password', app%password)
call dm_config_get(config, 'count', app%count)
call dm_config_get(config, 'interval', app%interval)
call dm_config_get(config, 'debug', app%debug)
call dm_config_get(config, 'verbose', app%verbose)
end if

call dm_config_close(config)
Expand Down
29 changes: 14 additions & 15 deletions app/dmdb.f90
Original file line number Diff line number Diff line change
Expand Up @@ -118,20 +118,20 @@ integer function read_args(app) result(rc)
rc = dm_arg_read(args, APP_NAME, APP_MAJOR, APP_MINOR, APP_PATCH, version)
if (dm_is_error(rc)) return

rc = dm_arg_get(args(1), app%name)
rc = dm_arg_get(args(2), app%config)
call dm_arg_get(args(1), app%name)
call dm_arg_get(args(2), app%config)

! Read configuration from file.
rc = read_config(app)
if (dm_is_error(rc)) return

! Overwrite configuration.
rc = dm_arg_get(args(3), app%logger)
rc = dm_arg_get(args(4), app%database)
rc = dm_arg_get(args(5), app%node)
rc = dm_arg_get(args(6), app%debug)
rc = dm_arg_get(args(7), app%ipc)
rc = dm_arg_get(args(8), app%verbose)
call dm_arg_get(args(3), app%logger)
call dm_arg_get(args(4), app%database)
call dm_arg_get(args(5), app%node)
call dm_arg_get(args(6), app%debug)
call dm_arg_get(args(7), app%ipc)
call dm_arg_get(args(8), app%verbose)

rc = E_INVALID

Expand Down Expand Up @@ -173,13 +173,12 @@ integer function read_config(app) result(rc)
rc = dm_config_open(config, app%config, app%name)

if (dm_is_ok(rc)) then
rc = dm_config_get(config, 'logger', app%logger)
rc = dm_config_get(config, 'database', app%database)
rc = dm_config_get(config, 'node', app%node)
rc = dm_config_get(config, 'debug', app%debug)
rc = dm_config_get(config, 'ipc', app%ipc)
rc = dm_config_get(config, 'verbose', app%verbose)
rc = E_NONE
call dm_config_get(config, 'logger', app%logger)
call dm_config_get(config, 'database', app%database)
call dm_config_get(config, 'node', app%node)
call dm_config_get(config, 'debug', app%debug)
call dm_config_get(config, 'ipc', app%ipc)
call dm_config_get(config, 'verbose', app%verbose)
end if

call dm_config_close(config)
Expand Down
68 changes: 34 additions & 34 deletions app/dmdbctl.f90
Original file line number Diff line number Diff line change
Expand Up @@ -444,62 +444,62 @@ integer function read_args(app) result(rc)

! Get entity type (node, sensor, target).
app%operation = sum(merge([1, 2, 3, 4], 0, mask))
rc = dm_arg_get(args(app%operation), type)
call dm_arg_get(args(app%operation), type)
app%type = dm_type_from_name(type)

! Get remaining command-line arguments.
rc = dm_arg_get(args(5), app%database)
call dm_arg_get(args(5), app%database)

select case (app%type)
case (TYPE_NODE)
! Get node attributes.
rc = dm_arg_get(args( 6), app%node%id)
rc = dm_arg_get(args( 7), app%node%name, passed=app%mask(ATTR_NAME))
rc = dm_arg_get(args( 8), app%node%meta, passed=app%mask(ATTR_META))
rc = dm_arg_get(args(13), app%node%x, passed=app%mask(ATTR_X))
rc = dm_arg_get(args(14), app%node%y, passed=app%mask(ATTR_Y))
rc = dm_arg_get(args(15), app%node%z, passed=app%mask(ATTR_Z))
rc = dm_arg_get(args(16), app%node%lon, passed=app%mask(ATTR_LON))
rc = dm_arg_get(args(17), app%node%lat, passed=app%mask(ATTR_LAT))
rc = dm_arg_get(args(18), app%node%alt, passed=app%mask(ATTR_ALT))
call dm_arg_get(args( 6), app%node%id)
call dm_arg_get(args( 7), app%node%name, passed=app%mask(ATTR_NAME))
call dm_arg_get(args( 8), app%node%meta, passed=app%mask(ATTR_META))
call dm_arg_get(args(13), app%node%x, passed=app%mask(ATTR_X))
call dm_arg_get(args(14), app%node%y, passed=app%mask(ATTR_Y))
call dm_arg_get(args(15), app%node%z, passed=app%mask(ATTR_Z))
call dm_arg_get(args(16), app%node%lon, passed=app%mask(ATTR_LON))
call dm_arg_get(args(17), app%node%lat, passed=app%mask(ATTR_LAT))
call dm_arg_get(args(18), app%node%alt, passed=app%mask(ATTR_ALT))

case (TYPE_SENSOR)
! Get sensor attributes.
rc = dm_arg_get(args( 6), app%sensor%id)
rc = dm_arg_get(args( 7), app%sensor%name, passed=app%mask(ATTR_NAME))
rc = dm_arg_get(args( 8), app%sensor%meta, passed=app%mask(ATTR_META))
rc = dm_arg_get(args( 9), app%sensor%node_id, passed=app%mask(ATTR_NODE))
rc = dm_arg_get(args(10), app%sensor%sn, passed=app%mask(ATTR_SN))
rc = dm_arg_get(args(11), sensor, passed=app%mask(ATTR_TYPE), default=SENSOR_TYPE_NAMES(SENSOR_TYPE_NONE))
rc = dm_arg_get(args(13), app%sensor%x, passed=app%mask(ATTR_X))
rc = dm_arg_get(args(14), app%sensor%y, passed=app%mask(ATTR_Y))
rc = dm_arg_get(args(15), app%sensor%z, passed=app%mask(ATTR_Z))
rc = dm_arg_get(args(16), app%sensor%lon, passed=app%mask(ATTR_LON))
rc = dm_arg_get(args(17), app%sensor%lat, passed=app%mask(ATTR_LAT))
rc = dm_arg_get(args(18), app%sensor%alt, passed=app%mask(ATTR_ALT))
call dm_arg_get(args( 6), app%sensor%id)
call dm_arg_get(args( 7), app%sensor%name, passed=app%mask(ATTR_NAME))
call dm_arg_get(args( 8), app%sensor%meta, passed=app%mask(ATTR_META))
call dm_arg_get(args( 9), app%sensor%node_id, passed=app%mask(ATTR_NODE))
call dm_arg_get(args(10), app%sensor%sn, passed=app%mask(ATTR_SN))
call dm_arg_get(args(11), sensor, passed=app%mask(ATTR_TYPE), default=SENSOR_TYPE_NAMES(SENSOR_TYPE_NONE))
call dm_arg_get(args(13), app%sensor%x, passed=app%mask(ATTR_X))
call dm_arg_get(args(14), app%sensor%y, passed=app%mask(ATTR_Y))
call dm_arg_get(args(15), app%sensor%z, passed=app%mask(ATTR_Z))
call dm_arg_get(args(16), app%sensor%lon, passed=app%mask(ATTR_LON))
call dm_arg_get(args(17), app%sensor%lat, passed=app%mask(ATTR_LAT))
call dm_arg_get(args(18), app%sensor%alt, passed=app%mask(ATTR_ALT))

app%sensor%type = dm_sensor_type_from_name(sensor)

case (TYPE_TARGET)
! Get target attributes.
rc = dm_arg_get(args( 6), app%target%id)
rc = dm_arg_get(args( 7), app%target%name, passed=app%mask(ATTR_NAME))
rc = dm_arg_get(args( 8), app%target%meta, passed=app%mask(ATTR_META))
rc = dm_arg_get(args(12), app%target%state, passed=app%mask(ATTR_STATE))
rc = dm_arg_get(args(13), app%target%x, passed=app%mask(ATTR_X))
rc = dm_arg_get(args(14), app%target%y, passed=app%mask(ATTR_Y))
rc = dm_arg_get(args(15), app%target%z, passed=app%mask(ATTR_Z))
rc = dm_arg_get(args(16), app%target%lon, passed=app%mask(ATTR_LON))
rc = dm_arg_get(args(17), app%target%lat, passed=app%mask(ATTR_LAT))
rc = dm_arg_get(args(18), app%target%alt, passed=app%mask(ATTR_ALT))
call dm_arg_get(args( 6), app%target%id)
call dm_arg_get(args( 7), app%target%name, passed=app%mask(ATTR_NAME))
call dm_arg_get(args( 8), app%target%meta, passed=app%mask(ATTR_META))
call dm_arg_get(args(12), app%target%state, passed=app%mask(ATTR_STATE))
call dm_arg_get(args(13), app%target%x, passed=app%mask(ATTR_X))
call dm_arg_get(args(14), app%target%y, passed=app%mask(ATTR_Y))
call dm_arg_get(args(15), app%target%z, passed=app%mask(ATTR_Z))
call dm_arg_get(args(16), app%target%lon, passed=app%mask(ATTR_LON))
call dm_arg_get(args(17), app%target%lat, passed=app%mask(ATTR_LAT))
call dm_arg_get(args(18), app%target%alt, passed=app%mask(ATTR_ALT))

case default
rc = E_INVALID
call dm_error_out(rc, 'invalid data type ' // trim(type) // ' (either node, sensor, or target)')
return
end select

rc = dm_arg_get(args(19), app%verbose)
call dm_arg_get(args(19), app%verbose)

! Validate options.
rc = E_INVALID
Expand Down
24 changes: 12 additions & 12 deletions app/dmexport.f90
Original file line number Diff line number Diff line change
Expand Up @@ -208,18 +208,18 @@ integer function read_args(app) result(rc)
rc = dm_arg_read(args, APP_NAME, APP_MAJOR, APP_MINOR, APP_PATCH, dm_db_version(.true.))
if (dm_is_error(rc)) return

rc = dm_arg_get(args( 1), app%database)
rc = dm_arg_get(args( 2), app%output)
rc = dm_arg_get(args( 3), app%node)
rc = dm_arg_get(args( 4), app%sensor)
rc = dm_arg_get(args( 5), app%target)
rc = dm_arg_get(args( 6), app%from)
rc = dm_arg_get(args( 7), app%to)
rc = dm_arg_get(args( 8), app%response)
rc = dm_arg_get(args( 9), format_name)
rc = dm_arg_get(args(10), type_name)
rc = dm_arg_get(args(11), app%header)
rc = dm_arg_get(args(12), app%separator)
call dm_arg_get(args( 1), app%database)
call dm_arg_get(args( 2), app%output)
call dm_arg_get(args( 3), app%node)
call dm_arg_get(args( 4), app%sensor)
call dm_arg_get(args( 5), app%target)
call dm_arg_get(args( 6), app%from)
call dm_arg_get(args( 7), app%to)
call dm_arg_get(args( 8), app%response)
call dm_arg_get(args( 9), format_name)
call dm_arg_get(args(10), type_name)
call dm_arg_get(args(11), app%header)
call dm_arg_get(args(12), app%separator)

app%format = dm_format_from_name(format_name)
app%type = dm_type_from_name(type_name)
Expand Down
61 changes: 30 additions & 31 deletions app/dmfeed.f90
Original file line number Diff line number Diff line change
Expand Up @@ -106,28 +106,28 @@ integer function read_args(app) result(rc)
rc = dm_arg_read(args, APP_NAME, APP_MAJOR, APP_MINOR, APP_PATCH, dm_db_version(.true.))
if (dm_is_error(rc)) return

rc = dm_arg_get(args(1), app%name)
rc = dm_arg_get(args(2), app%config)
call dm_arg_get(args(1), app%name)
call dm_arg_get(args(2), app%config)

! Read configuration from file.
rc = read_config(app)
if (dm_is_error(rc)) return

! Get all other arguments.
rc = dm_arg_get(args( 3), app%database)
rc = dm_arg_get(args( 4), app%output)
rc = dm_arg_get(args( 5), app%node)
rc = dm_arg_get(args( 6), app%entries)
rc = dm_arg_get(args( 7), app%min_level)
rc = dm_arg_get(args( 8), app%max_level)
rc = dm_arg_get(args( 9), app%force)
rc = dm_arg_get(args(10), app%atom%author)
rc = dm_arg_get(args(11), app%atom%email)
rc = dm_arg_get(args(12), app%atom%id)
rc = dm_arg_get(args(13), app%atom%title)
rc = dm_arg_get(args(14), app%atom%subtitle)
rc = dm_arg_get(args(15), app%atom%url)
rc = dm_arg_get(args(16), app%atom%xsl)
call dm_arg_get(args( 3), app%database)
call dm_arg_get(args( 4), app%output)
call dm_arg_get(args( 5), app%node)
call dm_arg_get(args( 6), app%entries)
call dm_arg_get(args( 7), app%min_level)
call dm_arg_get(args( 8), app%max_level)
call dm_arg_get(args( 9), app%force)
call dm_arg_get(args(10), app%atom%author)
call dm_arg_get(args(11), app%atom%email)
call dm_arg_get(args(12), app%atom%id)
call dm_arg_get(args(13), app%atom%title)
call dm_arg_get(args(14), app%atom%subtitle)
call dm_arg_get(args(15), app%atom%url)
call dm_arg_get(args(16), app%atom%xsl)

! Validate passed options.
rc = E_INVALID
Expand Down Expand Up @@ -181,21 +181,20 @@ integer function read_config(app) result(rc)
rc = dm_config_open(config, app%config, app%name)

if (dm_is_ok(rc)) then
rc = dm_config_get(config, 'database', app%database)
rc = dm_config_get(config, 'output', app%output)
rc = dm_config_get(config, 'node', app%node)
rc = dm_config_get(config, 'entries', app%entries)
rc = dm_config_get(config, 'minlevel', app%min_level)
rc = dm_config_get(config, 'maxlevel', app%max_level)
rc = dm_config_get(config, 'force', app%force)
rc = dm_config_get(config, 'author', app%atom%author)
rc = dm_config_get(config, 'email', app%atom%email)
rc = dm_config_get(config, 'id', app%atom%id)
rc = dm_config_get(config, 'title', app%atom%title)
rc = dm_config_get(config, 'subtitle', app%atom%subtitle)
rc = dm_config_get(config, 'url', app%atom%url)
rc = dm_config_get(config, 'xsl', app%atom%xsl)
rc = E_NONE
call dm_config_get(config, 'database', app%database)
call dm_config_get(config, 'output', app%output)
call dm_config_get(config, 'node', app%node)
call dm_config_get(config, 'entries', app%entries)
call dm_config_get(config, 'minlevel', app%min_level)
call dm_config_get(config, 'maxlevel', app%max_level)
call dm_config_get(config, 'force', app%force)
call dm_config_get(config, 'author', app%atom%author)
call dm_config_get(config, 'email', app%atom%email)
call dm_config_get(config, 'id', app%atom%id)
call dm_config_get(config, 'title', app%atom%title)
call dm_config_get(config, 'subtitle', app%atom%subtitle)
call dm_config_get(config, 'url', app%atom%url)
call dm_config_get(config, 'xsl', app%atom%xsl)
end if

call dm_config_close(config)
Expand Down
Loading

0 comments on commit 42231f8

Please sign in to comment.