Skip to content

Commit

Permalink
Added version callback to arg parsing.
Browse files Browse the repository at this point in the history
  • Loading branch information
interkosmos committed Nov 18, 2024
1 parent 8c09462 commit ad37901
Show file tree
Hide file tree
Showing 26 changed files with 168 additions and 90 deletions.
7 changes: 6 additions & 1 deletion app/dmbackup.f90
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ integer function read_args(app) result(rc)
]

! Read all command-line arguments.
rc = dm_arg_read(args, APP_NAME, APP_MAJOR, APP_MINOR, APP_PATCH, dm_db_version(.true.))
rc = dm_arg_read(args, version_callback)
if (dm_is_error(rc)) return

call dm_arg_get(args(1), app%database)
Expand Down Expand Up @@ -125,4 +125,9 @@ subroutine backup_handler(remaining, page_count)
write (*, '(a1, "[0GProgress: ", f5.1, " %")', advance='no') &
ASCII_ESC, 100.0 * (page_count - remaining) / page_count
end subroutine backup_handler

subroutine version_callback()
call dm_version_out(APP_NAME, APP_MAJOR, APP_MINOR, APP_PATCH)
print '(a)', dm_db_version(.true.)
end subroutine version_callback
end program dmbackup
11 changes: 7 additions & 4 deletions app/dmbeat.f90
Original file line number Diff line number Diff line change
Expand Up @@ -79,8 +79,7 @@ integer function read_args(app) result(rc)
!! Reads command-line arguments and settings from configuration file.
type(app_type), intent(out) :: app !! App type.

character(len=:), allocatable :: version
type(arg_type) :: args(14)
type(arg_type) :: args(14)

args = [ &
arg_type('name', short='n', type=ARG_TYPE_ID), & ! -n, --name <id>
Expand All @@ -100,8 +99,7 @@ integer function read_args(app) result(rc)
]

! Read all command-line arguments.
version = dm_rpc_version() // ' ' // dm_lua_version(.true.) // ' ' // dm_zstd_version(.true.)
rc = dm_arg_read(args, APP_NAME, APP_MAJOR, APP_MINOR, APP_PATCH, version)
rc = dm_arg_read(args, version_callback)
if (dm_is_error(rc)) return

call dm_arg_get(args(1), app%name)
Expand Down Expand Up @@ -344,4 +342,9 @@ subroutine signal_callback(signum) bind(c)
call dm_stop(STOP_SUCCESS)
end select
end subroutine signal_callback

subroutine version_callback()
call dm_version_out(APP_NAME, APP_MAJOR, APP_MINOR, APP_PATCH)
print '(a, 2(1x, a))', dm_rpc_version(), dm_lua_version(.true.), dm_zstd_version(.true.)
end subroutine version_callback
end program dmbeat
11 changes: 7 additions & 4 deletions app/dmbot.f90
Original file line number Diff line number Diff line change
Expand Up @@ -171,8 +171,7 @@ integer function read_args(app, bot) result(rc)
type(app_type), intent(out) :: app !! App type.
type(bot_type), intent(out) :: bot !! Bot type.

character(len=:), allocatable :: version
type(arg_type) :: args(12)
type(arg_type) :: args(12)

args = [ &
arg_type('name', short='n', type=ARG_TYPE_ID), & ! -n, --name <id>
Expand All @@ -190,8 +189,7 @@ integer function read_args(app, bot) result(rc)
]

! Read all command-line arguments.
version = dm_lua_version(.true.) // ' ' // dm_db_version(.true.)
rc = dm_arg_read(args, APP_NAME, APP_MAJOR, APP_MINOR, APP_PATCH, version)
rc = dm_arg_read(args, version_callback)
if (dm_is_error(rc)) return

call dm_arg_get(args(1), app%name)
Expand Down Expand Up @@ -909,4 +907,9 @@ subroutine signal_callback(signum) bind(c)
call halt(E_NONE)
end select
end subroutine signal_callback

subroutine version_callback()
call dm_version_out(APP_NAME, APP_MAJOR, APP_MINOR, APP_PATCH)
print '(a, 1x, a)', dm_lua_version(.true.), dm_db_version(.true.)
end subroutine version_callback
end program dmbot
11 changes: 7 additions & 4 deletions app/dmdb.f90
Original file line number Diff line number Diff line change
Expand Up @@ -96,8 +96,7 @@ integer function read_args(app) result(rc)
!! Reads command-line arguments and settings from configuration file.
type(app_type), intent(out) :: app

character(len=:), allocatable :: version
type(arg_type) :: args(8)
type(arg_type) :: args(8)

! Required and optional command-line arguments.
args = [ &
Expand All @@ -112,8 +111,7 @@ integer function read_args(app) result(rc)
]

! Read all command-line arguments.
version = dm_lua_version(.true.) // ' ' // dm_db_version(.true.)
rc = dm_arg_read(args, APP_NAME, APP_MAJOR, APP_MINOR, APP_PATCH, version)
rc = dm_arg_read(args, version_callback)
if (dm_is_error(rc)) return

call dm_arg_get(args(1), app%name)
Expand Down Expand Up @@ -295,4 +293,9 @@ subroutine signal_callback(signum) bind(c)
call halt(E_NONE)
end select
end subroutine signal_callback

subroutine version_callback()
call dm_version_out(APP_NAME, APP_MAJOR, APP_MINOR, APP_PATCH)
print '(a, 1x, a)', dm_lua_version(.true.), dm_db_version(.true.)
end subroutine version_callback
end program dmdb
7 changes: 6 additions & 1 deletion app/dmdbctl.f90
Original file line number Diff line number Diff line change
Expand Up @@ -419,7 +419,7 @@ integer function read_args(app) result(rc)
]

! Read command-line arguments.
rc = dm_arg_read(args, APP_NAME, APP_MAJOR, APP_MINOR, APP_PATCH, dm_db_version(.true.))
rc = dm_arg_read(args, version_callback)
if (dm_is_error(rc)) return

! CRUD operation.
Expand Down Expand Up @@ -553,4 +553,9 @@ integer function read_args(app) result(rc)
! Validation passed.
rc = E_NONE
end function read_args

subroutine version_callback()
call dm_version_out(APP_NAME, APP_MAJOR, APP_MINOR, APP_PATCH)
print '(a)', dm_db_version(.true.)
end subroutine version_callback
end program dmdbctl
7 changes: 6 additions & 1 deletion app/dmexport.f90
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,7 @@ integer function read_args(app) result(rc)
]

! Read all command-line arguments.
rc = dm_arg_read(args, APP_NAME, APP_MAJOR, APP_MINOR, APP_PATCH, dm_db_version(.true.))
rc = dm_arg_read(args, version_callback)
if (dm_is_error(rc)) return

call dm_arg_get(args( 1), app%database)
Expand Down Expand Up @@ -267,4 +267,9 @@ integer function read_args(app) result(rc)

rc = E_NONE
end function read_args

subroutine version_callback()
call dm_version_out(APP_NAME, APP_MAJOR, APP_MINOR, APP_PATCH)
print '(a)', dm_db_version(.true.)
end subroutine version_callback
end program dmexport
11 changes: 7 additions & 4 deletions app/dmfeed.f90
Original file line number Diff line number Diff line change
Expand Up @@ -77,8 +77,7 @@ integer function read_args(app) result(rc)
!! `--config` is passed).
type(app_type), intent(out) :: app !! App type.

character(len=:), allocatable :: version
type(arg_type) :: args(16)
type(arg_type) :: args(16)

args = [ &
arg_type('name', short='n', type=ARG_TYPE_ID), & ! -n, --name <id>
Expand All @@ -100,8 +99,7 @@ integer function read_args(app) result(rc)
]

! Read all command-line arguments.
version = dm_lua_version(.true.) // ' ' // dm_db_version(.true.)
rc = dm_arg_read(args, APP_NAME, APP_MAJOR, APP_MINOR, APP_PATCH, version)
rc = dm_arg_read(args, version_callback)
if (dm_is_error(rc)) return

call dm_arg_get(args(1), app%name)
Expand Down Expand Up @@ -274,4 +272,9 @@ subroutine create_feed(app, error)
if (present(error)) error = rc
rc = dm_db_close(db)
end subroutine create_feed

subroutine version_callback()
call dm_version_out(APP_NAME, APP_MAJOR, APP_MINOR, APP_PATCH)
print '(a, 1x, a)', dm_lua_version(.true.), dm_db_version(.true.)
end subroutine version_callback
end program dmfeed
7 changes: 6 additions & 1 deletion app/dmfs.f90
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ integer function read_args(app) result(rc)
]

! Read all command-line arguments.
rc = dm_arg_read(args, APP_NAME, APP_MAJOR, APP_MINOR, APP_PATCH, dm_lua_version(.true.))
rc = dm_arg_read(args, version_callback)
if (dm_is_error(rc)) return

call dm_arg_get(args(1), app%name)
Expand Down Expand Up @@ -467,4 +467,9 @@ subroutine signal_callback(signum) bind(c)
call dm_stop(STOP_SUCCESS)
end select
end subroutine signal_callback

subroutine version_callback()
call dm_version_out(APP_NAME, APP_MAJOR, APP_MINOR, APP_PATCH)
print '(a)', dm_lua_version(.true.)
end subroutine version_callback
end program dmfs
7 changes: 6 additions & 1 deletion app/dmgrc.f90
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ integer function read_args(app) result(rc)
]

! Read all command-line arguments.
rc = dm_arg_read(args, APP_NAME, APP_MAJOR, APP_MINOR, APP_PATCH, dm_lua_version(.true.))
rc = dm_arg_read(args, version_callback)
if (dm_is_error(rc)) return

call dm_arg_get(args(1), app%name)
Expand Down Expand Up @@ -306,4 +306,9 @@ subroutine signal_callback(signum) bind(c)
call halt(E_NONE)
end select
end subroutine signal_callback

subroutine version_callback()
call dm_version_out(APP_NAME, APP_MAJOR, APP_MINOR, APP_PATCH)
print '(a)', dm_lua_version(.true.)
end subroutine version_callback
end program dmgrc
7 changes: 6 additions & 1 deletion app/dmimport.f90
Original file line number Diff line number Diff line change
Expand Up @@ -270,7 +270,7 @@ integer function read_args(app) result(rc)
]

! Read all command-line arguments.
rc = dm_arg_read(args, APP_NAME, APP_MAJOR, APP_MINOR, APP_PATCH, dm_db_version(.true.))
rc = dm_arg_read(args, version_callback)
if (dm_is_error(rc)) return

call dm_arg_get(args(1), type_name)
Expand Down Expand Up @@ -308,4 +308,9 @@ integer function read_args(app) result(rc)

rc = E_NONE
end function read_args

subroutine version_callback()
call dm_version_out(APP_NAME, APP_MAJOR, APP_MINOR, APP_PATCH)
print '(a)', dm_db_version(.true.)
end subroutine version_callback
end program dmimport
7 changes: 6 additions & 1 deletion app/dminfo.f90
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ integer function read_args(app) result(rc)
arg_type(name='database', short='d', type=ARG_TYPE_DATABASE) & ! -d, --database <path>
]

rc = dm_arg_read(args, APP_NAME, APP_MAJOR, APP_MINOR, APP_PATCH, dm_db_version(.true.))
rc = dm_arg_read(args, version_callback)
call dm_arg_get(args(1), app%database)
rc = E_NONE
end function read_args
Expand Down Expand Up @@ -145,4 +145,9 @@ integer function output_info(app) result(rc)
print '("system.time.zone: ", a)', dm_time_zone()
print '("system.version: ", a)', trim(uname%version)
end function output_info

subroutine version_callback()
call dm_version_out(APP_NAME, APP_MAJOR, APP_MINOR, APP_PATCH)
print '(a)', dm_db_version(.true.)
end subroutine version_callback
end program dminfo
7 changes: 6 additions & 1 deletion app/dminit.f90
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ integer function read_args(app) result(rc)
]

! Read all command-line arguments.
rc = dm_arg_read(args, APP_NAME, APP_MAJOR, APP_MINOR, APP_PATCH, dm_db_version(.true.))
rc = dm_arg_read(args, version_callback)
if (dm_is_error(rc)) return

! Database type (observ, log, beat).
Expand Down Expand Up @@ -130,4 +130,9 @@ integer function read_args(app) result(rc)

rc = E_NONE
end function read_args

subroutine version_callback()
call dm_version_out(APP_NAME, APP_MAJOR, APP_MINOR, APP_PATCH)
print '(a)', dm_db_version(.true.)
end subroutine version_callback
end program dminit
6 changes: 5 additions & 1 deletion app/dmlog.f90
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ integer function read_args(app, log) result(rc)
]

! Read all command-line arguments.
rc = dm_arg_read(args, APP_NAME, APP_MAJOR, APP_MINOR, APP_PATCH)
rc = dm_arg_read(args, version_callback)
if (dm_is_error(rc)) return

call dm_arg_get(args( 1), app%logger)
Expand All @@ -85,4 +85,8 @@ integer function read_args(app, log) result(rc)

rc = E_NONE
end function read_args

subroutine version_callback()
call dm_version_out(APP_NAME, APP_MAJOR, APP_MINOR, APP_PATCH)
end subroutine version_callback
end program dmlog
11 changes: 7 additions & 4 deletions app/dmlogger.f90
Original file line number Diff line number Diff line change
Expand Up @@ -92,8 +92,7 @@ integer function read_args(app) result(rc)
!! Reads command-line arguments and settings from configuration file.
type(app_type), intent(out) :: app

character(len=:), allocatable :: version
type(arg_type) :: args(7)
type(arg_type) :: args(7)

! Required and optional command-line arguments.
args = [ &
Expand All @@ -107,8 +106,7 @@ integer function read_args(app) result(rc)
]

! Read all command-line arguments.
version = dm_lua_version(.true.) // ' ' // dm_db_version(.true.)
rc = dm_arg_read(args, APP_NAME, APP_MAJOR, APP_MINOR, APP_PATCH, version)
rc = dm_arg_read(args, version_callback)
if (dm_is_error(rc)) return

call dm_arg_get(args(1), app%name)
Expand Down Expand Up @@ -289,4 +287,9 @@ subroutine signal_callback(signum) bind(c)
call halt(0)
end select
end subroutine signal_callback

subroutine version_callback()
call dm_version_out(APP_NAME, APP_MAJOR, APP_MINOR, APP_PATCH)
print '(a, 1x, a)', dm_lua_version(.true.), dm_db_version(.true.)
end subroutine version_callback
end program dmlogger
7 changes: 6 additions & 1 deletion app/dmlua.f90
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ integer function read_args(app) result(rc)
]

! Read all command-line arguments.
rc = dm_arg_read(args, APP_NAME, APP_MAJOR, APP_MINOR, APP_PATCH, dm_lua_version(.true.))
rc = dm_arg_read(args, version_callback)
if (dm_is_error(rc)) return

call dm_arg_get(args(1), app%name)
Expand Down Expand Up @@ -319,4 +319,9 @@ subroutine signal_callback(signum) bind(c)
call halt(E_NONE)
end select
end subroutine signal_callback

subroutine version_callback()
call dm_version_out(APP_NAME, APP_MAJOR, APP_MINOR, APP_PATCH)
print '(a)', dm_lua_version(.true.)
end subroutine version_callback
end program dmlua
7 changes: 6 additions & 1 deletion app/dmmbctl.f90
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ integer function read_args(app) result(rc)
]

! Read all command-line arguments.
rc = dm_arg_read(args, APP_NAME, APP_MAJOR, APP_MINOR, APP_PATCH, dm_modbus_version(.true.))
rc = dm_arg_read(args, version_callback)
if (dm_is_error(rc)) return

call dm_arg_get(args( 1), app%rtu%path, passed=has_path)
Expand Down Expand Up @@ -286,4 +286,9 @@ integer function read_args(app) result(rc)

rc = E_NONE
end function read_args

subroutine version_callback()
call dm_version_out(APP_NAME, APP_MAJOR, APP_MINOR, APP_PATCH)
print '(a)', dm_modbus_version(.true.)
end subroutine version_callback
end program dmmbctl
7 changes: 6 additions & 1 deletion app/dmpipe.f90
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ integer function read_args(app) result(rc)
]

! Read all command-line arguments.
rc = dm_arg_read(args, APP_NAME, APP_MAJOR, APP_MINOR, APP_PATCH, dm_lua_version(.true.))
rc = dm_arg_read(args, version_callback)
if (dm_is_error(rc)) return

call dm_arg_get(args(1), app%name)
Expand Down Expand Up @@ -452,4 +452,9 @@ subroutine signal_callback(signum) bind(c)
call dm_stop(STOP_SUCCESS)
end select
end subroutine signal_callback

subroutine version_callback()
call dm_version_out(APP_NAME, APP_MAJOR, APP_MINOR, APP_PATCH)
print '(a)', dm_lua_version(.true.)
end subroutine version_callback
end program dmpipe
Loading

0 comments on commit ad37901

Please sign in to comment.