#!/bin/bash -e

PATH="${PATH}:/usr/share/con-dev" . con-lib.bash
con::include opt

# Main usage
commands_usage="\
Example demonstrating con-libopt: Script with individual commands.

See example ``positionals`` for a more complete list of option variants.

-g        : Common main option.
-R <regex>: Regex for option variables to print.
 default=[^_]\+\$"

# Common usage for all commands.
commands_cmd_usage="\
-j: Common option for all commands."

# A 'top level' command
commands_cmd_status_usage="\
Print all variables set by libopt.

-s: Option for status only."
commands:cmd:status()
{
	con::opt:debug:printVars "${main_opt_R}"
}

# Group "net": Commands may be grouped (separating subcommands via "_")
# Groups may have a common usage as well.
commands_cmd_net_usage="\
Commands all around the network.

Adds nice and useless little commands around your
networks.

-i <iface>: Interface to use. Common option for the 'net' command group.
 type=choice:i-default:i-given:eth0:eth1:wlan0:wlan1
 default=i-default"

# Commands may have init functions on any level ("after cmd:")
commands:cmd:__init__()
{
	con::log:notice "Common init code for any command."
}

commands:cmd:net:__init__()
{
	con::log:notice "Init code for the net command group."
	declare -g COMMANDS_NET_INIT_CALLED="true"
}

commands_cmd_net_status_usage="\
Show network status."
commands:cmd:net_status()
{
	[ "${COMMANDS_NET_INIT_CALLED}" = "true" ]
	con::opt:debug:printVars "${main_opt_R}"
}

commands_cmd_net_up_usage="\
Bring the network up, then run <script>.

<script>: Run this script after network is up
 type=file"

commands:cmd:net_up()
{
	[ "${COMMANDS_NET_INIT_CALLED}" = "true" ]
	con::opt:debug:printVars "${main_opt_R}"
}

con_opt::run "${@}"
