/**************************************************************************************
 *
 *     Project:    kvmstoreserver-tools
 *     File name:  cmdParser.go
 *     Version:    1.0.0
 *     Date:       2018-01-15
 *
 *     Autor:      Bogdanovic Theodor
 *     Contact:    t.bogdanovic@hotmail.com
 *
 *     License:    GPLv3
 *
 **************************************************************************************/
/**************************************************************************************
 * Copyright 2018 Bogdanovic Theodor
 *
 * This file is part of kvmstoreserver-tools.
 *
 * kvmstoreserver-tools 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 3 of the License, or
 * (at your option) any later version.
 *
 * kvmstoreserver-tools 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 kvmstoreserver-tools.  If not, see <http://www.gnu.org/licenses/>.
 **************************************************************************************/
/**************************************************************************************
 *  Further explanations:  This source code is under the license specified by the
 *                         Autor above. Core components or other packages are still
 *                         in source code form, under the license specified by the
 *                         respective author.
 **************************************************************************************/

package utils

import (
	"checker"
	"flag"
	"fmt"
	"log"
	"os"
)

//*****************************************************************************
//*
//*      Structure: CmdController
//*
//*****************************************************************************

// CmdController ...
type CmdController struct {
	target *string
	start  *int
}

//******************** Methods ************************************************

// GetTarget ...
func (slf *CmdController) GetTarget() string { return *slf.target }

// GetStart ...
func (slf *CmdController) GetStart() int { return *slf.start }

//*****************************************************************************
//*
//*      Public Functions
//*
//*****************************************************************************

// NewCmdController ...
func NewCmdController() *CmdController {

	var cmdController CmdController

	cmdController.target = flag.String("target", "",
		"The URL to the storeserver -> EXAMPLE: http://<IP or domain name>:3344")

	cmdController.start = flag.Int("start", 0,
		"Please enter the start number. At this point + 6000 will be added")

	if cmdController.target == nil {
		fmt.Println("Please enter the address of the server -> EXAMPLE: inject_client -target http://<IP or domain name>:3344")
		os.Exit(1)
	}

	flag.Parse()

	if err := checker.IsURLValid(*cmdController.target); err != nil {
		log.Fatal(err)
	}

	return &cmdController
}
