Search in sources :

Example 1 with OptionModel

use of org.eclipse.ceylon.common.tool.OptionModel in project ceylon by eclipse.

the class DocBuilder method buildRootSynopsis.

private SynopsesSection buildRootSynopsis(ToolModel<?> model) {
    SynopsesSection synopsis = new SynopsesSection();
    synopsis.setTitle(CeylonHelpToolMessages.msg("section.SYNOPSIS"));
    List<Synopsis> synopsisList = new ArrayList<>();
    {
        Synopsis s1 = new Synopsis();
        s1.setInvocation(Tools.progName());
        OptionModel<Boolean> option = new OptionModel<>();
        option.setLongName("version");
        option.setArgumentType(ArgumentType.BOOLEAN);
        ArgumentModel<Boolean> argument = new ArgumentModel<>();
        argument.setMultiplicity(Multiplicity._1);
        argument.setType(Boolean.TYPE);
        option.setArgument(argument);
        // model.getOption("version")));
        s1.setOptionsAndArguments(Collections.singletonList(option));
        synopsisList.add(s1);
    }
    {
        Synopsis s2 = new Synopsis();
        s2.setInvocation(Tools.progName());
        ArrayList<Object> args = new ArrayList<Object>(model.getOptions());
        args.remove(model.getOption("version"));
        /*ArgumentModel<?> options = new ArgumentModel();
            options.setMultiplicity(Multiplicity._0_OR_MORE);
            options.setName("cey\u2011options");
            args.add(options);*/
        ArgumentModel<?> command = new ArgumentModel<>();
        command.setMultiplicity(Multiplicity._1);
        command.setName("command");
        args.add(command);
        ArgumentModel<?> commandOptions = new ArgumentModel<>();
        commandOptions.setMultiplicity(Multiplicity._0_OR_MORE);
        commandOptions.setName("command\u2011options");
        args.add(commandOptions);
        ArgumentModel<?> commandArgs = new ArgumentModel<>();
        commandArgs.setMultiplicity(Multiplicity._0_OR_MORE);
        commandArgs.setName("command\u2011args");
        args.add(commandArgs);
        s2.setOptionsAndArguments(args);
        synopsisList.add(s2);
    }
    synopsis.setSynopses(synopsisList);
    return synopsis;
}
Also used : ArgumentModel(org.eclipse.ceylon.common.tool.ArgumentModel) ArrayList(java.util.ArrayList) OptionModel(org.eclipse.ceylon.common.tool.OptionModel) SynopsesSection(org.eclipse.ceylon.common.tools.help.model.SynopsesSection) Synopsis(org.eclipse.ceylon.common.tools.help.model.Synopsis)

Example 2 with OptionModel

use of org.eclipse.ceylon.common.tool.OptionModel in project ceylon by eclipse.

the class DocBuilder method buildOptions.

private OptionsSection buildOptions(ToolModel<?> model) {
    if (!(model instanceof AnnotatedToolModel))
        return null;
    final HashMap<ToolModel<?>, OptionsSection> map = new HashMap<>();
    new SubtoolVisitor(model) {

        @Override
        protected void visit(ToolModel<?> model, SubtoolModel<?> subtoolModel) {
            OptionsSection optionsSection = new OptionsSection();
            map.put(model, optionsSection);
            if (model == root) {
                optionsSection.setTitle(Markdown.markdown("##" + CeylonHelpToolMessages.msg("section.OPTIONS")));
            } else {
                optionsSection.setTitle(Markdown.markdown("###" + CeylonHelpToolMessages.msg("section.OPTIONS.sub", model.getName())));
            }
            List<Option> options = new ArrayList<>();
            for (OptionModel<?> opt : sortedOptions(model.getOptions())) {
                Option option = new Option();
                option.setOption(opt);
                String descriptionMd = getOptionDescription(model, opt);
                if (descriptionMd == null || descriptionMd.isEmpty()) {
                    descriptionMd = CeylonHelpToolMessages.msg("option.undocumented");
                }
                option.setDescription(Markdown.markdown(descriptionMd));
                options.add(option);
            }
            optionsSection.setOptions(options);
            if (model != root && !options.isEmpty()) {
                OptionsSection parent = map.get(ancestors.lastElement().getModel());
                ArrayList<OptionsSection> parentSubsections = new ArrayList<OptionsSection>(parent.getSubsections());
                parentSubsections.add(optionsSection);
                parent.setSubsections(parentSubsections);
            }
        }
    }.accept();
    return map.get(model);
}
Also used : HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) SubtoolVisitor(org.eclipse.ceylon.common.tools.help.model.SubtoolVisitor) AnnotatedToolModel(org.eclipse.ceylon.common.tool.AnnotatedToolModel) PluginToolModel(org.eclipse.ceylon.common.tool.PluginToolModel) AnnotatedToolModel(org.eclipse.ceylon.common.tool.AnnotatedToolModel) ToolModel(org.eclipse.ceylon.common.tool.ToolModel) ScriptToolModel(org.eclipse.ceylon.common.tool.ScriptToolModel) OptionsSection(org.eclipse.ceylon.common.tools.help.model.OptionsSection) OptionModel(org.eclipse.ceylon.common.tool.OptionModel) ArrayList(java.util.ArrayList) List(java.util.List) Option(org.eclipse.ceylon.common.tools.help.model.Option)

Aggregations

ArrayList (java.util.ArrayList)2 OptionModel (org.eclipse.ceylon.common.tool.OptionModel)2 HashMap (java.util.HashMap)1 List (java.util.List)1 AnnotatedToolModel (org.eclipse.ceylon.common.tool.AnnotatedToolModel)1 ArgumentModel (org.eclipse.ceylon.common.tool.ArgumentModel)1 PluginToolModel (org.eclipse.ceylon.common.tool.PluginToolModel)1 ScriptToolModel (org.eclipse.ceylon.common.tool.ScriptToolModel)1 ToolModel (org.eclipse.ceylon.common.tool.ToolModel)1 Option (org.eclipse.ceylon.common.tools.help.model.Option)1 OptionsSection (org.eclipse.ceylon.common.tools.help.model.OptionsSection)1 SubtoolVisitor (org.eclipse.ceylon.common.tools.help.model.SubtoolVisitor)1 SynopsesSection (org.eclipse.ceylon.common.tools.help.model.SynopsesSection)1 Synopsis (org.eclipse.ceylon.common.tools.help.model.Synopsis)1