/**
 * File:
 *  groups.ycp
 * Module:
 *  Configuration of the users and groups stettings
 *
 * Summary:
 *  Main file.
 *
 * Authors:
 *	Jiri Suchomel <jsuchome@suse.cz>
 *
 * $Id: groups.ycp 20044 2004-10-29 09:49:28Z jsuchome $
 *
 * Just a shortcut to invoke groups management
 */

{

textdomain "users";

y2milestone ("----------------------------------------");
y2milestone ("Users module started");

import "CommandLine";
import "Mode";
import "Users";
import "UsersCache";

include "users/wizards.ycp";
include "users/cmdline.ycp";

string  start_dialog	= "summary";
any	ret		= nil;
integer arg		= 0;
list    possible_start_dialogs = ["group_add", "summary", "users", "groups" ];
// do not pass arguments to cmd-line interpreter
boolean no_cmdline	= false;

while ( arg < size( WFM::Args() ) )
{
    any a = WFM::Args( arg );
    if ( is (a, string) && contains( possible_start_dialogs, a))
    {
	start_dialog = (string) WFM::Args( arg );
	no_cmdline		= true;
    }
    arg = arg + 1;
}

// default for this client
UsersCache::SetCurrentSummary ("groups");

if (start_dialog == "users" || start_dialog == "groups")
{
    UsersCache::SetCurrentSummary (start_dialog);
    start_dialog	= "summary";
}

if (no_cmdline)
{
    y2milestone( "Starting with %1 - test mode: %2", start_dialog, Mode::test () );
    Users::SetStartDialog (start_dialog);
    ret = UsersSequence (start_dialog);
    y2milestone("Users module finished with %1", ret);
    y2milestone("----------------------------------------");
    return ret;
}

// else parse arguments in cmdline
y2milestone( "Starting with arguments: %1", WFM::Args() );


/* the command line description map */
map cmdline = $[
    "id"		: "groups",
    // translators: command line help text for Users module
    "help"		: _("Group configuration module."),
    "guihandler"	: UsersGUI,
    "initialize"	: UsersRead,
    "finish"		: UsersWrite,
    "actions"		: $[
	"list" :$[
	    "handler"	: GroupsListHandler,
	    // translators: command line help text for list action
	    "help"	: _("List of available groups"),
	    "options"	: [ "non_strict" ],
	    // help text for unknown parameter name
	    "non_strict_help":	_("User parameters that should be listed"),
	],
	"show" :$[
	    "handler"	: GroupShowHandler,
	    // translators: command line help text for show action
	    "help"	: _("Show information of selected group")
	],
	"delete" :$[
	    "handler"	: GroupDeleteHandler,
	    // translators: command line help text for delete action
	    "help"	: _("Delete an existing group")
	],
	"add" :$[
	    "handler"	: GroupAddHandler,
	    // translators: command line help text for ad action
	    "help"	: _("Add new group"),
	    "options"   : ["non_strict"],
	    // help text for unknown parameter name
	    "non_strict_help":	_("Additional (LDAP) group parameters"),
	],
	"edit" :$[
	    "handler"	: GroupEditHandler,
	    // translators: command line help text for ad action
	    "help"	: _("Edit an existing group"),
	    "options"   : ["non_strict"],
	    // help text for unknown parameter name
	    "non_strict_help":	_("Additional (LDAP) group parameters"),
	],
    ],
    "options"		: $[
	"local"	:$[
	    // translators: command line help text for list local option
	    "help"	: _("List of local groups"),
	],
	"system"	:$[
	    // translators: command line help text for list system option
	    "help"	: _("List of system groups"),
	],
	"ldap"		:$[
	    // translators: command line help text for list ldap option
	    "help"	: _("List of LDAP groups"),
	],
	"nis"		:$[
	    // translators: command line help text for list nis option
	    "help"	: _("List of NIS groups"),
	],
	"gid"		:$[
	    // translators: command line help text for show uid option
	    "help"	: _("GID of the group"),
	    "type"	: "string"
	],
	"groupname"	:$[
	    // translators: command line help text for groupname option
	    "help"	: _("Name of the group"),
	    "type"	: "string"
	],
	"password"		:$[
	    // translators: command line help text for 'password' option
	    "help"	: _("Password of the group"),
	    "type"	: "string"
	],
	"userlist"	:$[
	    // translators: command line help text for 'user' option
	    "help"	: _("List of group members, usually user names, separated by commas. The list of LDAP user DNs must be separated by colons."),
	    "type"	: "string"
	],
	"new_groupname"	:$[
	    // translators: command line help text for new_groupname option
	    "help"	: _("New group name"),
	    "type"	: "string"
	],
	"new_gid"		:$[
	    // translators: command line help text for new_gid option
	    "help"	: _("New GID of the group"),
	    "type"	: "string"
	],
	"type"	:$[
	    // translators: command line help text for show option
	    "help"	: _("Type of the group (local, system, nis, ldap)"),
	    "type"	: "string"
	],
	"ldap_password"	:$[
	    // translators: command line help text for ldap_password option
	    "help"	: _("Password for LDAP server"),
	    "type"	: "string"
	],
    ],
    "mappings"		: $[
	"list"	: [ "local", "system", "ldap", "nis" ],// + "custom"
	"show"  : [ "gid", "groupname", "type"],
	"delete": [ "groupname", "gid", "type", "ldap_password" ],
	"add"	: [ "groupname", "gid", "password", "userlist", "type", "ldap_password"],
	"edit"	: [ "groupname", "gid", "password", "new_gid", "userlist", "new_groupname", "type", "ldap_password" ],
    ]
];

ret = CommandLine::Run (cmdline);

y2milestone("Users module finished with %1", ret);
y2milestone("----------------------------------------");
return ret;

} // End
