# Path: marathoner/commands/base.py
# class BaseCommand(object):
#     syntax = ''
#     help = ''
# 
#     def __init__(self, project, executor):
#         self.project = project
#         self.executor = executor
#         self.contest = project.contest
# 
#     def is_match(self, command):
#         '''Given is the text that user typed into command line, return True
#         if this command should execute.
#         '''
#         raise NotImplementedError()
# 
#     def handle(self, command):
#         '''Given is the text that user typed into command line, execute the
#         command.
#         '''
# 
# class CommandSyntaxError(Exception):
#     pass


import re
from six import print_
from marathoner.commands.base import BaseCommand, CommandSyntaxError




class Command(BaseCommand):
    syntax = 'hash [<tag>]'
    help = 'output the hash of the current or selected tag'

    cmd_re = re.compile(r'^\s*hash(?:\s+(\w+))?\s*$', re.IGNORECASE)
    match_re = re.compile(r'^\s*hash\b', re.IGNORECASE)

    def is_match(self, command):
        return self.match_re.match(command)

    def handle(self, command):
        match = self.cmd_re.match(command)
        if not match:
            raise CommandSyntaxError

        tag_name = match.group(1)
        if tag_name is None:
            print_(self.project.source_hash)
        else:

# Path: marathoner/commands/base.py
# class BaseCommand(object):
#     syntax = ''
#     help = ''
# 
#     def __init__(self, project, executor):
#         self.project = project
#         self.executor = executor
#         self.contest = project.contest
# 
#     def is_match(self, command):
#         '''Given is the text that user typed into command line, return True
#         if this command should execute.
#         '''
#         raise NotImplementedError()
# 
#     def handle(self, command):
#         '''Given is the text that user typed into command line, execute the
#         command.
#         '''
# 
# class CommandSyntaxError(Exception):
#     pass


# Path: marathoner/commands/hash.py
import re
from six import print_
from marathoner.commands.base import BaseCommand, CommandSyntaxError





class Command(BaseCommand):
    syntax = 'hash [<tag>]'
    help = 'output the hash of the current or selected tag'

    cmd_re = re.compile(r'^\s*hash(?:\s+(\w+))?\s*$', re.IGNORECASE)
    match_re = re.compile(r'^\s*hash\b', re.IGNORECASE)

    def is_match(self, command):
        return self.match_re.match(command)

    def handle(self, command):
        match = self.cmd_re.match(command)
        if not match:
            raise CommandSyntaxError

        tag_name = match.group(1)
        if tag_name is None:
            print_(self.project.source_hash)
        else:

            tag = self.project.tags.get(tag_name)