# Path: shovel/parser.py
# def parse(tokens):
#     '''Parse the provided string to produce *args and **kwargs'''
#     args = []
#     kwargs = {}
#     last = None
#     for token in tokens:
#         if token.startswith('--'):
#             # If this is a keyword flag, but we've already got one that we've
#             # parsed, then we're going to interpret it as a bool
#             if last:
#                 kwargs[last] = True
#             # See if it is the --foo=5 style
#             last, _, value = token.strip('-').partition('=')
#             if value:
#                 kwargs[last] = value
#                 last = None
#         elif last != None:
#             kwargs[last] = token
#             last = None
#         else:
#             args.append(token)
# 
#     # If there's a dangling last, set that bool
#     if last:
#         kwargs[last] = True
# 
#     return args, kwargs


import unittest
from shovel.parser import parse
#! /usr/bin/env python

'''Ensure our CLI parsing works'''



class TestParse(unittest.TestCase):
    '''Test our argspec wrapper'''
    def test_basic(self):
        '''A few low-ball examples'''
        args, kwargs = parse('1 2 3 4 5'.split(' '))
        self.assertEqual(args, ['1', '2', '3', '4', '5'])
        self.assertEqual(kwargs, {})

        # Make sure we handle bool flags
        args, kwargs = parse('--foo --bar --whiz'.split(' '))
        self.assertEqual(args, [])
        self.assertEqual(kwargs, {'foo': True, 'bar': True, 'whiz': True})

        # Make sure we can handle interleaved positional and keyword args

# Path: shovel/parser.py
# def parse(tokens):
#     '''Parse the provided string to produce *args and **kwargs'''
#     args = []
#     kwargs = {}
#     last = None
#     for token in tokens:
#         if token.startswith('--'):
#             # If this is a keyword flag, but we've already got one that we've
#             # parsed, then we're going to interpret it as a bool
#             if last:
#                 kwargs[last] = True
#             # See if it is the --foo=5 style
#             last, _, value = token.strip('-').partition('=')
#             if value:
#                 kwargs[last] = value
#                 last = None
#         elif last != None:
#             kwargs[last] = token
#             last = None
#         else:
#             args.append(token)
# 
#     # If there's a dangling last, set that bool
#     if last:
#         kwargs[last] = True
# 
#     return args, kwargs


# Path: test/test_parse.py
import unittest
from shovel.parser import parse

#! /usr/bin/env python

'''Ensure our CLI parsing works'''



class TestParse(unittest.TestCase):
    '''Test our argspec wrapper'''
    def test_basic(self):
        '''A few low-ball examples'''
        args, kwargs = parse('1 2 3 4 5'.split(' '))
        self.assertEqual(args, ['1', '2', '3', '4', '5'])
        self.assertEqual(kwargs, {})

        # Make sure we handle bool flags
        args, kwargs = parse('--foo --bar --whiz'.split(' '))
        self.assertEqual(args, [])
        self.assertEqual(kwargs, {'foo': True, 'bar': True, 'whiz': True})

        # Make sure we can handle interleaved positional and keyword args

        args, kwargs = parse('1 --foo 5 2 3'.split(' '))