Search in sources :

Example 1 with Parameter

use of com.beust.jcommander.Parameter in project copybara by google.

the class MarkdownGenerator method generateFlagsInfo.

private CharSequence generateFlagsInfo(Element classElement) throws ElementException {
    StringBuilder sb = new StringBuilder();
    AnnotationHelper<UsesFlags> annotation = annotationHelper(classElement, UsesFlags.class);
    if (annotation == null) {
        return sb;
    }
    StringBuilder flagsString = new StringBuilder();
    for (DeclaredType flag : annotation.getClassListValue("value")) {
        Element flagClass = flag.asElement();
        for (Element member : flagClass.getEnclosedElements()) {
            Parameter flagAnnotation = member.getAnnotation(Parameter.class);
            if (flagAnnotation == null || !(member instanceof VariableElement) || flagAnnotation.hidden()) {
                continue;
            }
            VariableElement field = (VariableElement) member;
            flagsString.append(Joiner.on(", ").join(flagAnnotation.names()));
            flagsString.append(" | *");
            flagsString.append(simplerJavaTypes(field));
            flagsString.append("* | ");
            flagsString.append(flagAnnotation.description());
            flagsString.append("\n");
        }
    }
    if (flagsString.length() > 0) {
        sb.append("\n\n**Command line flags:**\n\n");
        sb.append("Name | Type | Description\n");
        sb.append("---- | ----------- | -----------\n");
        sb.append(flagsString);
        sb.append("\n");
    }
    return sb;
}
Also used : UsesFlags(com.google.copybara.doc.annotations.UsesFlags) VariableElement(javax.lang.model.element.VariableElement) TypeElement(javax.lang.model.element.TypeElement) ExecutableElement(javax.lang.model.element.ExecutableElement) DocElement(com.google.copybara.doc.annotations.DocElement) Element(javax.lang.model.element.Element) Parameter(com.beust.jcommander.Parameter) VariableElement(javax.lang.model.element.VariableElement) DeclaredType(javax.lang.model.type.DeclaredType)

Example 2 with Parameter

use of com.beust.jcommander.Parameter in project mixcr by milaboratory.

the class ActionAssembleContigs method go.

@Override
public void go(ActionHelper helper) throws Exception {
    // TODO FIX!!!!!!!!!!!!!
    if (parameters.threads > 1)
        throw new ParameterException("Multithreaded processing is not supported yet.");
    long beginTimestamp = System.currentTimeMillis();
    FullSeqAssemblerParameters p = FullSeqAssemblerParameters.getByName("default");
    if (!parameters.overrides.isEmpty()) {
        // Perform parameters overriding
        p = JsonOverrider.override(p, FullSeqAssemblerParameters.class, parameters.overrides);
        if (p == null)
            throw new ProcessException("Failed to override some parameter.");
    }
    final FullSeqAssemblerReport report = new FullSeqAssemblerReport();
    FullSeqAssemblerParameters assemblerParameters = p;
    int totalClonesCount = 0;
    List<VDJCGene> genes;
    VDJCAlignerParameters alignerParameters;
    CloneAssemblerParameters cloneAssemblerParameters;
    try (ClnAReader reader = new ClnAReader(parameters.getInputFileName(), VDJCLibraryRegistry.getDefault());
        PrimitivO tmpOut = new PrimitivO(new BufferedOutputStream(new FileOutputStream(parameters.getOutputFileName())))) {
        final CloneFactory cloneFactory = new CloneFactory(reader.getAssemblerParameters().getCloneFactoryParameters(), reader.getAssemblingFeatures(), reader.getGenes(), reader.getAlignerParameters().getFeaturesToAlignMap());
        alignerParameters = reader.getAlignerParameters();
        cloneAssemblerParameters = reader.getAssemblerParameters();
        genes = reader.getGenes();
        IOUtil.registerGeneReferences(tmpOut, genes, alignerParameters);
        ClnAReader.CloneAlignmentsPort cloneAlignmentsPort = reader.clonesAndAlignments();
        SmartProgressReporter.startProgressReport("Assembling", cloneAlignmentsPort);
        OutputPort<Clone[]> parallelProcessor = new ParallelProcessor<>(cloneAlignmentsPort, cloneAlignments -> {
            FullSeqAssembler fullSeqAssembler = new FullSeqAssembler(cloneFactory, assemblerParameters, cloneAlignments.clone, alignerParameters);
            fullSeqAssembler.setReport(report);
            FullSeqAssembler.RawVariantsData rawVariantsData = fullSeqAssembler.calculateRawData(() -> {
                try {
                    return cloneAlignments.alignments();
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            });
            return fullSeqAssembler.callVariants(rawVariantsData);
        }, parameters.threads);
        for (Clone[] clones : CUtils.it(parallelProcessor)) {
            totalClonesCount += clones.length;
            for (Clone cl : clones) tmpOut.writeObject(cl);
        }
        assert report.getInitialCloneCount() == reader.numberOfClones();
    }
    assert report.getFinalCloneCount() == totalClonesCount;
    assert report.getFinalCloneCount() >= report.getInitialCloneCount();
    Clone[] clones = new Clone[totalClonesCount];
    try (PrimitivI tmpIn = new PrimitivI(new BufferedInputStream(new FileInputStream(parameters.getOutputFileName())))) {
        IOUtil.registerGeneReferences(tmpIn, genes, alignerParameters);
        int i = 0;
        for (Clone clone : CUtils.it(new PipeDataInputReader<>(Clone.class, tmpIn, totalClonesCount))) clones[i++] = clone;
    }
    Arrays.sort(clones, Comparator.comparingDouble(c -> -c.getCount()));
    for (int i = 0; i < clones.length; i++) clones[i] = clones[i].setId(i);
    CloneSet cloneSet = new CloneSet(Arrays.asList(clones), genes, alignerParameters.getFeaturesToAlignMap(), alignerParameters, cloneAssemblerParameters);
    try (CloneSetIO.CloneSetWriter writer = new CloneSetIO.CloneSetWriter(cloneSet, parameters.getOutputFileName())) {
        SmartProgressReporter.startProgressReport(writer);
        writer.write();
    }
    ReportWrapper reportWrapper = new ReportWrapper(command(), report);
    reportWrapper.setStartMillis(beginTimestamp);
    reportWrapper.setInputFiles(parameters.getInputFileName());
    reportWrapper.setOutputFiles(parameters.getOutputFileName());
    reportWrapper.setCommandLine(helper.getCommandLineArguments());
    reportWrapper.setFinishMillis(System.currentTimeMillis());
    // Writing report to stout
    System.out.println("============= Report ==============");
    Util.writeReportToStdout(report);
    if (parameters.report != null)
        Util.writeReport(parameters.report, reportWrapper);
    if (parameters.jsonReport != null)
        Util.writeJsonReport(parameters.jsonReport, reportWrapper);
}
Also used : Parameters(com.beust.jcommander.Parameters) java.util(java.util) ParameterException(com.beust.jcommander.ParameterException) Action(com.milaboratory.cli.Action) Parameter(com.beust.jcommander.Parameter) CloneAssemblerParameters(com.milaboratory.mixcr.assembler.CloneAssemblerParameters) com.milaboratory.mixcr.basictypes(com.milaboratory.mixcr.basictypes) FullSeqAssemblerParameters(com.milaboratory.mixcr.assembler.fullseq.FullSeqAssemblerParameters) ParallelProcessor(cc.redberry.pipe.blocks.ParallelProcessor) VDJCAlignerParameters(com.milaboratory.mixcr.vdjaligners.VDJCAlignerParameters) PositiveInteger(com.beust.jcommander.validators.PositiveInteger) CloneFactory(com.milaboratory.mixcr.assembler.CloneFactory) FullSeqAssembler(com.milaboratory.mixcr.assembler.fullseq.FullSeqAssembler) ActionHelper(com.milaboratory.cli.ActionHelper) PrimitivO(com.milaboratory.primitivio.PrimitivO) CUtils(cc.redberry.pipe.CUtils) FullSeqAssemblerReport(com.milaboratory.mixcr.assembler.fullseq.FullSeqAssemblerReport) PrimitivI(com.milaboratory.primitivio.PrimitivI) OutputPort(cc.redberry.pipe.OutputPort) PipeDataInputReader(com.milaboratory.primitivio.PipeDataInputReader) java.io(java.io) VDJCGene(io.repseq.core.VDJCGene) SmartProgressReporter(com.milaboratory.util.SmartProgressReporter) DynamicParameter(com.beust.jcommander.DynamicParameter) VDJCLibraryRegistry(io.repseq.core.VDJCLibraryRegistry) ProcessException(com.milaboratory.cli.ProcessException) ActionParametersWithOutput(com.milaboratory.cli.ActionParametersWithOutput) VDJCAlignerParameters(com.milaboratory.mixcr.vdjaligners.VDJCAlignerParameters) FullSeqAssemblerParameters(com.milaboratory.mixcr.assembler.fullseq.FullSeqAssemblerParameters) CloneAssemblerParameters(com.milaboratory.mixcr.assembler.CloneAssemblerParameters) ParallelProcessor(cc.redberry.pipe.blocks.ParallelProcessor) ParameterException(com.beust.jcommander.ParameterException) PrimitivO(com.milaboratory.primitivio.PrimitivO) FullSeqAssembler(com.milaboratory.mixcr.assembler.fullseq.FullSeqAssembler) FullSeqAssemblerReport(com.milaboratory.mixcr.assembler.fullseq.FullSeqAssemblerReport) ProcessException(com.milaboratory.cli.ProcessException) VDJCGene(io.repseq.core.VDJCGene) CloneFactory(com.milaboratory.mixcr.assembler.CloneFactory) PrimitivI(com.milaboratory.primitivio.PrimitivI)

Example 3 with Parameter

use of com.beust.jcommander.Parameter in project halyard by spinnaker.

the class NestableCommand method commandDocs.

private void commandDocs(StringBuilder result) {
    List<ParameterDescription> parameters = commander.getParameters().stream().filter(p -> !p.getParameter().hidden()).collect(Collectors.toList());
    parameters.sort(Comparator.comparing(ParameterDescription::getNames));
    int parameterCount = 0;
    for (ParameterDescription parameter : parameters) {
        if (GlobalOptions.isGlobalOption(parameter.getLongestName())) {
            parameterCount++;
        }
    }
    String longDescription = getLongDescription() != null ? getLongDescription() : getDescription();
    result.append("## ").append(fullCommandName).append("\n\n").append(longDescription).append("\n\n").append("#### Usage").append("\n```\n").append(fullCommandName);
    ParameterDescription mainParameter = commander.getMainParameter();
    if (mainParameter != null) {
        result.append(" ").append(getMainParameter().toUpperCase());
    }
    if (parameters.size() > parameterCount) {
        result.append(" [parameters]");
    }
    if (!subcommands.isEmpty()) {
        result.append(" [subcommands]");
    }
    result.append("\n```\n");
    if (!parameters.isEmpty()) {
        if (getCommandName() == "hal") {
            result.append("#### Global Parameters\n");
        }
        for (ParameterDescription parameter : parameters) {
            if (GlobalOptions.isGlobalOption(parameter.getLongestName())) {
                // Omit printing global parameters for everything but the top-level command
                if (getCommandName() == "hal") {
                    parameterDoc(result, parameter);
                }
            }
        }
        result.append("\n");
    }
    if (parameters.size() > parameterCount) {
        result.append("#### Parameters\n");
        if (mainParameter != null) {
            result.append('`').append(getMainParameter().toUpperCase()).append('`').append(": ").append(mainParameter.getDescription()).append("\n");
        }
        for (ParameterDescription parameter : parameters) {
            if (!GlobalOptions.isGlobalOption(parameter.getLongestName())) {
                parameterDoc(result, parameter);
            }
        }
        result.append("\n");
    }
    if (!subcommands.isEmpty()) {
        result.append("#### Subcommands\n");
        List<String> keys = new ArrayList<>(subcommands.keySet());
        keys.sort(String::compareTo);
        for (String key : keys) {
            NestableCommand subcommand = subcommands.get(key);
            String modifiers = "";
            if (subcommand instanceof DeprecatedCommand) {
                modifiers += " _(Deprecated)_ ";
            }
            String shortDescription = subcommand.getShortDescription() != null ? subcommand.getShortDescription() : subcommand.getDescription();
            result.append(" * ").append("`").append(key).append("`").append(modifiers).append(": ").append(shortDescription).append("\n");
        }
    }
    result.append("\n---\n");
}
Also used : Parameters(com.beust.jcommander.Parameters) Setter(lombok.Setter) ExpectedDaemonFailureException(com.netflix.spinnaker.halyard.cli.services.v1.ExpectedDaemonFailureException) Getter(lombok.Getter) Parameter(com.beust.jcommander.Parameter) HashMap(java.util.HashMap) AnsiFormatUtils(com.netflix.spinnaker.halyard.cli.ui.v1.AnsiFormatUtils) ArrayList(java.util.ArrayList) AccessLevel(lombok.AccessLevel) JobExecutor(com.netflix.spinnaker.halyard.core.job.v1.JobExecutor) Map(java.util.Map) ThreadLocalRandom(java.util.concurrent.ThreadLocalRandom) FormatConverter(com.netflix.spinnaker.halyard.cli.command.v1.converter.FormatConverter) Console(java.io.Console) ConnectException(java.net.ConnectException) AnsiParagraphBuilder(com.netflix.spinnaker.halyard.cli.ui.v1.AnsiParagraphBuilder) AnsiStoryBuilder(com.netflix.spinnaker.halyard.cli.ui.v1.AnsiStoryBuilder) AnsiStyle(com.netflix.spinnaker.halyard.cli.ui.v1.AnsiStyle) ParameterDescription(com.beust.jcommander.ParameterDescription) AnsiUi(com.netflix.spinnaker.halyard.cli.ui.v1.AnsiUi) JCommander(com.beust.jcommander.JCommander) AnsiPrinter(com.netflix.spinnaker.halyard.cli.ui.v1.AnsiPrinter) Collectors(java.util.stream.Collectors) JobExecutorLocal(com.netflix.spinnaker.halyard.core.job.v1.JobExecutorLocal) LogLevelConverter(com.netflix.spinnaker.halyard.cli.command.v1.converter.LogLevelConverter) TaskKilledException(com.netflix.spinnaker.halyard.cli.services.v1.TaskKilledException) Level(ch.qos.logback.classic.Level) List(java.util.List) RetrofitError(retrofit.RetrofitError) TreeMap(java.util.TreeMap) StringReplaceJarResource(com.netflix.spinnaker.halyard.core.resource.v1.StringReplaceJarResource) Comparator(java.util.Comparator) ArrayList(java.util.ArrayList) ParameterDescription(com.beust.jcommander.ParameterDescription)

Aggregations

Parameter (com.beust.jcommander.Parameter)3 Parameters (com.beust.jcommander.Parameters)2 CUtils (cc.redberry.pipe.CUtils)1 OutputPort (cc.redberry.pipe.OutputPort)1 ParallelProcessor (cc.redberry.pipe.blocks.ParallelProcessor)1 Level (ch.qos.logback.classic.Level)1 DynamicParameter (com.beust.jcommander.DynamicParameter)1 JCommander (com.beust.jcommander.JCommander)1 ParameterDescription (com.beust.jcommander.ParameterDescription)1 ParameterException (com.beust.jcommander.ParameterException)1 PositiveInteger (com.beust.jcommander.validators.PositiveInteger)1 DocElement (com.google.copybara.doc.annotations.DocElement)1 UsesFlags (com.google.copybara.doc.annotations.UsesFlags)1 Action (com.milaboratory.cli.Action)1 ActionHelper (com.milaboratory.cli.ActionHelper)1 ActionParametersWithOutput (com.milaboratory.cli.ActionParametersWithOutput)1 ProcessException (com.milaboratory.cli.ProcessException)1 CloneAssemblerParameters (com.milaboratory.mixcr.assembler.CloneAssemblerParameters)1 CloneFactory (com.milaboratory.mixcr.assembler.CloneFactory)1 FullSeqAssembler (com.milaboratory.mixcr.assembler.fullseq.FullSeqAssembler)1