#!/bin/sh

# 	Copyright (c) 2005-2007 ALT Linux, Peter V. Saveliev
#
# 	This file is part of Connexion project.
#
# 	Connexion is free software; you can redistribute it and/or modify
# 	it under the terms of the GNU General Public License as published by
# 	the Free Software Foundation; either version 2 of the License, or
# 	(at your option) any later version.
#
# 	Connexion is distributed in the hope that it will be useful,
# 	but WITHOUT ANY WARRANTY; without even the implied warranty of
# 	MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# 	GNU General Public License for more details.
#
# 	You should have received a copy of the GNU General Public License
# 	along with Connexion; if not, write to the Free Software
# 	Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA


## intercept -h and add own help (examples)
[ -z "` echo \"-- $@\" | sed 's/.*\ -h.*//' `" ] && {
	{
	connexion-cli -s /var/run/connexion/socket "$@"
	echo -e "
Ncsh examples:
	See examples in the connexion-doc package. Short examples:

1. \033[01;04mCreate IPv4 address on an interface\033[0m
shell > configure network interfaces ethernet 0
ethernet 0 > address 10.0.0.1/24
ethernet 0 > commit

2. \033[01;04mRemove IPv4 address from an interface\033[0m
shell > configure network interfaces ethernet 0
ethernet 0 > no address 10.0.0.1/24
ethernet 0 > commit

3. \033[01;04mCreate VLAN 101 interface (way #1)\033[0m
shell > configure network interfaces ethernet 0.101
	# setup inteface
ethernet 0 > commit

4. \033[01;04mCreate VLAN 101 interface (way #2)\033[0m
shell > configure network interfaces ethernet 0
ethernet 0 > vlan 101
	# setup interface
vlan 101 > commit

5. \033[01;04mCreate a route\033[0m
shell > configure network routing table
table > route default via 10.0.0.1
table > commit

6. \033[01;04mRemove a route\033[0m
shell > configure network routing table
table > no route default via 10.0.0.1
table > commit

7. \033[01;04mSee actual configuration:\033[0m tree
shell > tree
!
configure
	!
	network
		...

8. \033[01;04mSee pending changes:\033[0m transaction
shell > transaction
!
configure
	!
	network
		...

9. \033[01;04mJump to root context:\033[0m pop /
shell > configure network interfaces ethernet 0
ethernet 0 > vlan 101
vlan 101 > pop /
shell >

"
	} | less -R
} || {
	exec connexion-cli -s /var/run/connexion/socket "$@"
}

