# Path: fimfarchive/commands/base.py
# class Command(ABC):
#     """
#     Command line interface for tasks.
#     """
# 
#     @abstractmethod
#     def __call__(self, *args: str) -> int:
#         """
#         Runs the command.
# 
#         Args:
#             *args: Command line arguments.
# 
#         Returns:
#             Application exit status.
# 
#         Raises:
#             SystemExit: If the arguments are invalid.
#         """
# 
# Path: fimfarchive/commands/build.py
# class BuildCommand(Command):
#     """
#     Builds a new Fimfarchive release.
#     """
# 
#     @property
#     def parser(self) -> ArgumentParser:
#         """
#         Returns a command line arguments parser.
#         """
#         parser = ArgumentParser(
#             prog='',
#             description=self.__doc__,
#         )
# 
#         parser.add_argument(
#             '--archive',
#             help="previous version of the archive",
#             type=FileType('rb'),
#             required=True,
#             metavar='PATH',
#         )
# 
#         parser.add_argument(
#             '--output',
#             help="directory for the output archive",
#             default='worktree/build',
#         )
# 
#         parser.add_argument(
#             '--meta',
#             help="directory to fetch meta from",
#             default='worktree/update/meta',
#         )
# 
#         parser.add_argument(
#             '--data',
#             help="directory to fetch data from",
#             default='worktree/render/epub',
#         )
# 
#         parser.add_argument(
#             '--extras',
#             help="directory to fetch extras from",
#             default='worktree/extras',
#         )
# 
#         return parser
# 
#     def configure(self, opts: Namespace) -> BuildTask:
#         """
#         Returns a configured task instance.
# 
#         Args:
#             opts: Parsed command line arguments.
#         """
#         fimfarchive = FimfarchiveFetcher(
#             source=opts.archive,
#         )
# 
#         directory = DirectoryFetcher(
#             meta_path=opts.meta,
#             data_path=opts.data,
#             flavors=[DataFormat.EPUB],
#         )
# 
#         return BuildTask(
#             output=opts.output,
#             upcoming=tqdm(directory),
#             previous=fimfarchive,
#             extras=opts.extras,
#         )
# 
#     def __call__(self, *args):
#         opts = self.parser.parse_args(args)
#         task = self.configure(opts)
# 
#         task.run()
# 
#         return 0
# 
# Path: fimfarchive/commands/update.py
# class UpdateCommand(Command):
#     """
#     Updates stories for Fimfarchive.
#     """
# 
#     @property
#     def parser(self) -> ArgumentParser:
#         """
#         Returns a command line arguments parser.
#         """
#         parser = ArgumentParser(
#             prog='',
#             description=self.__doc__,
#         )
# 
#         parser.add_argument(
#             '--alpha',
#             help="fetch from Fimfiction APIv1",
#             action='store_true',
#         )
# 
#         parser.add_argument(
#             '--archive',
#             help="previous version of the archive",
#             type=FileType('rb'),
#             required=True,
#             metavar='PATH',
#         )
# 
#         parser.add_argument(
#             '--refetch',
#             help="refetch all available stories",
#             action='store_true',
#         )
# 
#         return parser
# 
#     def configure(self, opts: Namespace) -> UpdateTask:
#         """
#         Returns a configured task instance.
# 
#         Args:
#             opts: Parsed command line arguments.
#         """
#         fimfarchive: Fetcher
#         fimfiction: Fetcher
#         selector: Selector
# 
#         token = os.environ.get(ACCESS_TOKEN_KEY)
# 
#         if opts.alpha:
#             fimfiction = FimfictionFetcher()
#         elif token:
#             fimfiction = Fimfiction2Fetcher(token, True, opts.refetch)
#         else:
#             exit(f"Environment variable required: {ACCESS_TOKEN_KEY}")
# 
#         if opts.refetch:
#             selector = RefetchSelector()
#         else:
#             selector = UpdateSelector()
# 
#         print(f"\nStarted: {arrow.now()}")
#         print(f"Archive: {basename(opts.archive.name)}")
#         print(f"Fetcher: {type(fimfiction).__name__}")
#         print(f"Selector: {type(selector).__name__}")
# 
#         fimfarchive = FimfarchiveFetcher(opts.archive)
# 
#         return UpdateTask(
#             fimfarchive=fimfarchive,
#             fimfiction=fimfiction,
#             selector=selector,
#         )
# 
#     def __call__(self, *args):
#         opts = self.parser.parse_args(args)
#         task = self.configure(opts)
# 
#         with UpdatePrinter(task):
#             task.run()
# 
#         print(f"\nDone: {arrow.now()}")
# 
#         return 0


from typing import Dict, Type
from .base import Command
from .build import BuildCommand
from .update import UpdateCommand
#
# This program 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.
#
# This program 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 this program.  If not, see <http://www.gnu.org/licenses/>.
#





__all__ = (
    'RootCommand',
)


class RootCommand(Command):
    """
    The main application command.
    """
    commands: Dict[str, Type[Command]] = {
        'build': BuildCommand,

# Path: fimfarchive/commands/base.py
# class Command(ABC):
#     """
#     Command line interface for tasks.
#     """
# 
#     @abstractmethod
#     def __call__(self, *args: str) -> int:
#         """
#         Runs the command.
# 
#         Args:
#             *args: Command line arguments.
# 
#         Returns:
#             Application exit status.
# 
#         Raises:
#             SystemExit: If the arguments are invalid.
#         """
# 
# Path: fimfarchive/commands/build.py
# class BuildCommand(Command):
#     """
#     Builds a new Fimfarchive release.
#     """
# 
#     @property
#     def parser(self) -> ArgumentParser:
#         """
#         Returns a command line arguments parser.
#         """
#         parser = ArgumentParser(
#             prog='',
#             description=self.__doc__,
#         )
# 
#         parser.add_argument(
#             '--archive',
#             help="previous version of the archive",
#             type=FileType('rb'),
#             required=True,
#             metavar='PATH',
#         )
# 
#         parser.add_argument(
#             '--output',
#             help="directory for the output archive",
#             default='worktree/build',
#         )
# 
#         parser.add_argument(
#             '--meta',
#             help="directory to fetch meta from",
#             default='worktree/update/meta',
#         )
# 
#         parser.add_argument(
#             '--data',
#             help="directory to fetch data from",
#             default='worktree/render/epub',
#         )
# 
#         parser.add_argument(
#             '--extras',
#             help="directory to fetch extras from",
#             default='worktree/extras',
#         )
# 
#         return parser
# 
#     def configure(self, opts: Namespace) -> BuildTask:
#         """
#         Returns a configured task instance.
# 
#         Args:
#             opts: Parsed command line arguments.
#         """
#         fimfarchive = FimfarchiveFetcher(
#             source=opts.archive,
#         )
# 
#         directory = DirectoryFetcher(
#             meta_path=opts.meta,
#             data_path=opts.data,
#             flavors=[DataFormat.EPUB],
#         )
# 
#         return BuildTask(
#             output=opts.output,
#             upcoming=tqdm(directory),
#             previous=fimfarchive,
#             extras=opts.extras,
#         )
# 
#     def __call__(self, *args):
#         opts = self.parser.parse_args(args)
#         task = self.configure(opts)
# 
#         task.run()
# 
#         return 0
# 
# Path: fimfarchive/commands/update.py
# class UpdateCommand(Command):
#     """
#     Updates stories for Fimfarchive.
#     """
# 
#     @property
#     def parser(self) -> ArgumentParser:
#         """
#         Returns a command line arguments parser.
#         """
#         parser = ArgumentParser(
#             prog='',
#             description=self.__doc__,
#         )
# 
#         parser.add_argument(
#             '--alpha',
#             help="fetch from Fimfiction APIv1",
#             action='store_true',
#         )
# 
#         parser.add_argument(
#             '--archive',
#             help="previous version of the archive",
#             type=FileType('rb'),
#             required=True,
#             metavar='PATH',
#         )
# 
#         parser.add_argument(
#             '--refetch',
#             help="refetch all available stories",
#             action='store_true',
#         )
# 
#         return parser
# 
#     def configure(self, opts: Namespace) -> UpdateTask:
#         """
#         Returns a configured task instance.
# 
#         Args:
#             opts: Parsed command line arguments.
#         """
#         fimfarchive: Fetcher
#         fimfiction: Fetcher
#         selector: Selector
# 
#         token = os.environ.get(ACCESS_TOKEN_KEY)
# 
#         if opts.alpha:
#             fimfiction = FimfictionFetcher()
#         elif token:
#             fimfiction = Fimfiction2Fetcher(token, True, opts.refetch)
#         else:
#             exit(f"Environment variable required: {ACCESS_TOKEN_KEY}")
# 
#         if opts.refetch:
#             selector = RefetchSelector()
#         else:
#             selector = UpdateSelector()
# 
#         print(f"\nStarted: {arrow.now()}")
#         print(f"Archive: {basename(opts.archive.name)}")
#         print(f"Fetcher: {type(fimfiction).__name__}")
#         print(f"Selector: {type(selector).__name__}")
# 
#         fimfarchive = FimfarchiveFetcher(opts.archive)
# 
#         return UpdateTask(
#             fimfarchive=fimfarchive,
#             fimfiction=fimfiction,
#             selector=selector,
#         )
# 
#     def __call__(self, *args):
#         opts = self.parser.parse_args(args)
#         task = self.configure(opts)
# 
#         with UpdatePrinter(task):
#             task.run()
# 
#         print(f"\nDone: {arrow.now()}")
# 
#         return 0


# Path: fimfarchive/commands/root.py
from typing import Dict, Type
from .base import Command
from .build import BuildCommand
from .update import UpdateCommand

#
# This program 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.
#
# This program 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 this program.  If not, see <http://www.gnu.org/licenses/>.
#





__all__ = (
    'RootCommand',
)


class RootCommand(Command):
    """
    The main application command.
    """
    commands: Dict[str, Type[Command]] = {
        'build': BuildCommand,

        'update': UpdateCommand,