001/*
002 * SPDX-License-Identifier: Apache-2.0
003 *
004 * Copyright 2025-2026 The Enola <https://enola.dev> Authors
005 *
006 * Licensed under the Apache License, Version 2.0 (the "License");
007 * you may not use this file except in compliance with the License.
008 * You may obtain a copy of the License at
009 *
010 *     https://www.apache.org/licenses/LICENSE-2.0
011 *
012 * Unless required by applicable law or agreed to in writing, software
013 * distributed under the License is distributed on an "AS IS" BASIS,
014 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
015 * See the License for the specific language governing permissions and
016 * limitations under the License.
017 */
018package dev.enola.tool.todo.cli;
019
020import dev.enola.cli.common.Application;
021import dev.enola.cli.common.CLI;
022import dev.enola.cli.common.LocaleOption;
023import dev.enola.cli.common.LoggingMixin;
024import dev.enola.cli.common.VersionProvider;
025import dev.enola.common.io.mediatype.MediaTypeProviders;
026import dev.enola.common.io.mediatype.YamlMediaType;
027import dev.enola.tool.todo.ToDoRepository;
028import dev.enola.tool.todo.config.ToDoRepositorySupplier;
029
030import picocli.CommandLine.Command;
031import picocli.CommandLine.HelpCommand;
032import picocli.CommandLine.Mixin;
033
034@Command(
035        name = "todo",
036        mixinStandardHelpOptions = true,
037        showDefaultValues = true,
038        synopsisSubcommandLabel = "COMMAND",
039        description = "ToDo List Tool",
040        versionProvider = VersionProvider.class,
041        subcommands = {HelpCommand.class, ToDoAddCommand.class, ToDoListCommand.class})
042public class ToDoMain extends Application {
043
044    @Mixin LoggingMixin loggingMixin;
045    @Mixin LocaleOption localeOption;
046
047    ToDoRepository repository;
048
049    public static void main(String[] args) {
050        System.exit(cli(args).execute());
051    }
052
053    private static CLI cli(String... args) {
054        return new CLI(args, new ToDoMain());
055    }
056
057    @Override
058    protected void start() {
059        localeOption.initializeSINGLETON();
060
061        // TODO Use a shared Configuration class, like EnolaApplication does
062        if (!MediaTypeProviders.SINGLETON.isSet()) {
063            MediaTypeProviders.set(new YamlMediaType());
064        }
065
066        repository = new ToDoRepositorySupplier().get();
067    }
068}