#!/usr/bin/env python
"""
 SlipStream Client
 =====
 Copyright (C) 2013 SixSq Sarl (sixsq.com)
 =====
 Licensed under the Apache License, Version 2.0 (the "License");
 you may not use this file except in compliance with the License.
 You may obtain a copy of the License at

      http://www.apache.org/licenses/LICENSE-2.0

 Unless required by applicable law or agreed to in writing, software
 distributed under the License is distributed on an "AS IS" BASIS,
 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 See the License for the specific language governing permissions and
 limitations under the License.
"""
from __future__ import print_function

from slipstream.CommandBase import CommandBase
from slipstream.Client import Client
from slipstream.ConfigHolder import ConfigHolder


class MainProgram(CommandBase):
    '''A command-line program to set key/value pairs to info sys restlet.'''

    def __init__(self, argv=None):
        self.key = None
        self.value = None
        super(MainProgram, self).__init__(argv)

    def parse(self):
        usage = '''%prog [options] <key> [<value>]

<key>            Key from which to retrieve the value
<value>          Value to be set.  This parameter is mandatory, unless the
                 --decrement option is uses, in which case this parameter is
                 ignores'''

        self.parser.usage = usage

        self.addIgnoreAbortOption()

        self.options, self.args = self.parser.parse_args()

        if len(self.args) != 2:
                self.usageExit('Error, two argument must be specified')

        self.key = self.args[0]
        self.value = self.args[1]

    def doWork(self):
        configHolder = ConfigHolder(self.options)
        client = Client(configHolder)
        client.setRuntimeParameter(self.key, self.value)

if __name__ == "__main__":
    try:
        MainProgram()
    except KeyboardInterrupt:
        print('\n\nExecution interrupted by the user... goodbye!')
