Search in sources :

Example 1 with Synopsis

use of org.eclipse.ceylon.common.tools.help.model.Synopsis 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 Synopsis

use of org.eclipse.ceylon.common.tools.help.model.Synopsis in project ceylon by eclipse.

the class DocBuilder method buildSynopsis.

// private DescribedSection buildSubcommands(ToolModel<?> model) {
// /*
// DescribedSection section = null;
// if (!description.isEmpty()) {
// SubtoolModel<?> subtool = model.getSubtoolModel();
// for (String toolName : subtool.getToolLoader().getToolNames()) {
// ToolModel<Tool> subtoolModel = subtool.getToolLoader().loadToolModel(toolName);
// }
// / *
// * Here I need to build up the markdown something like as follows
// *
// The command `ceylon config` takes various subcommands
// 
// ## SUBCOMMANDS
// 
// ### `ceylon config foo`
// 
// summary
// 
// description
// 
// options
// 
// ### `ceylon config bar baz`
// 
// summary
// 
// description
// 
// options
// 
// * /
// section = new DescribedSection();
// section.setRole(Role.SUBCOMMANDS);
// section.setDescription(Markdown.markdown(
// "##" + sectionsBundle.getString("section.SUBCOMMANDS") + "\n\n" +
// description));
// }
// return section;*/
// return null;
// }
private SynopsesSection buildSynopsis(ToolModel<?> model) {
    // Synopsis synopsis = out.startSynopsis(bundle.getString("section.SYNOPSIS"));
    // TODO Make auto generated SYNOPSIS better -- we need to know which options
    // form groups, or should we just have a @Synopses({@Synopsis(""), ...})
    SynopsesSection synopsesSection = new SynopsesSection();
    synopsesSection.setTitle(CeylonHelpToolMessages.msg("section.SYNOPSIS"));
    final List<Synopsis> synopsisList = new ArrayList<>();
    new SubtoolVisitor(model) {

        @Override
        protected void visit(ToolModel<?> model, SubtoolModel<?> subtoolModel) {
            if (model.getSubtoolModel() == null) {
                // a leaf
                Synopsis synopsis = new Synopsis();
                synopsis.setInvocation(getCeylonInvocationForSynopsis(root));
                List<Object> optionsAndArguments;
                if (ancestors.isEmpty()) {
                    optionsAndArguments = optionsAndArguments(model);
                } else {
                    optionsAndArguments = new ArrayList<>();
                    for (SubtoolVisitor.ToolModelAndSubtoolModel ancestor : ancestors) {
                        List<Object> subOptAndArgs = optionsAndArguments(ancestor.getModel());
                        if (ancestor.getModel() != root) {
                            // Don't treat the foo in `ceylon foo` as a subtool
                            subOptAndArgs.add(0, ancestor);
                        }
                        optionsAndArguments.addAll(subOptAndArgs);
                    }
                    List<Object> subOptAndArgs = optionsAndArguments(model);
                    subOptAndArgs.add(0, new SubtoolVisitor.ToolModelAndSubtoolModel(model, subtoolModel));
                    optionsAndArguments.addAll(subOptAndArgs);
                }
                synopsis.setOptionsAndArguments(optionsAndArguments);
                synopsisList.add(synopsis);
            }
        }
    }.accept();
    synopsesSection.setSynopses(synopsisList);
    return synopsesSection;
}
Also used : ArrayList(java.util.ArrayList) ArrayList(java.util.ArrayList) List(java.util.List) SynopsesSection(org.eclipse.ceylon.common.tools.help.model.SynopsesSection) SubtoolVisitor(org.eclipse.ceylon.common.tools.help.model.SubtoolVisitor) Synopsis(org.eclipse.ceylon.common.tools.help.model.Synopsis)

Aggregations

ArrayList (java.util.ArrayList)2 SynopsesSection (org.eclipse.ceylon.common.tools.help.model.SynopsesSection)2 Synopsis (org.eclipse.ceylon.common.tools.help.model.Synopsis)2 List (java.util.List)1 ArgumentModel (org.eclipse.ceylon.common.tool.ArgumentModel)1 OptionModel (org.eclipse.ceylon.common.tool.OptionModel)1 SubtoolVisitor (org.eclipse.ceylon.common.tools.help.model.SubtoolVisitor)1