Skip to content
Draft
57 changes: 55 additions & 2 deletions modules/nextflow/src/main/groovy/nextflow/cli/CmdLineage.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ class CmdLineage extends CmdBase implements UsageAware {
void diff(ConfigMap config, List<String> args)
void find(ConfigMap config, List<String> args)
void check(ConfigMap config, List<String> args)
void validate(ConfigMap config, List<String> args)
}

interface SubCmd {
Expand All @@ -68,11 +69,21 @@ class CmdLineage extends CmdBase implements UsageAware {
commands << new CmdDiff()
commands << new CmdFind()
commands << new CmdCheck()
commands << new CmdValidate()
}

@Parameter(hidden = true)
List<String> args

@Parameter(names = ['-against'], description = 'Baseline lineage ID for the validate sub-command', hidden = true)
String validateAgainst

@Parameter(names = ['-ignore-fields'], description = 'Comma-separated fields to ignore in validate', hidden = true)
String validateIgnoreFields

@Parameter(names = ['-output-base'], description = 'Base path for output relativization in validate', hidden = true)
String validateOutputBase

@Override
String getName() {
return NAME
Expand All @@ -97,8 +108,18 @@ class CmdLineage extends CmdBase implements UsageAware {
this.operation = Plugins.getExtension(LinCommand)
if( !operation )
throw new IllegalStateException("Unable to load lineage extensions.")
// consume the first argument
getCmd(args).apply(args.drop(1))
// forward sub-command-level options consumed by JCommander
final subArgs = new ArrayList<String>(args.drop(1))
if( validateAgainst != null ) {
subArgs.add('--against'); subArgs.add(validateAgainst)
}
if( validateIgnoreFields != null ) {
subArgs.add('--ignore-fields'); subArgs.add(validateIgnoreFields)
}
if( validateOutputBase != null ) {
subArgs.add('--output-base'); subArgs.add(validateOutputBase)
}
getCmd(args).apply(subArgs)
}

/**
Expand Down Expand Up @@ -311,4 +332,36 @@ class CmdLineage extends CmdBase implements UsageAware {

}

class CmdValidate implements SubCmd {

@Override
String getName() { 'validate' }

@Override
String getDescription() {
return 'Validate that two workflow runs are semantically equivalent'
}

void apply(List<String> args) {
if (args.size() < 2) {
println("ERROR: Incorrect number of parameters")
usage()
return
}
operation.validate(config, args)
}

@Override
void usage() {
println description
println "Usage: nextflow $NAME $name <lid> -against <baseline-lid> [-ignore-fields field1,field2]"
println ""
println "Options:"
println " -against <lid> The baseline workflow run to compare against"
println " -ignore-fields <list> Comma-separated list of additional fields to ignore"
println " -output-base <path> Base path for relativizing output file paths"
}

}

}
19 changes: 19 additions & 0 deletions modules/nextflow/src/test/groovy/nextflow/cli/LauncherTest.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,25 @@ class LauncherTest extends Specification {
}


def 'should parse `lineage validate` with -against'() {
when:
def launcher = new Launcher().parseMainArgs('lineage','validate','lid://aaa','-against','lid://bbb')
then:
launcher.command instanceof CmdLineage
launcher.command.args == ['validate','lid://aaa']
launcher.command.validateAgainst == 'lid://bbb'
}

def 'should parse `lineage validate` with -ignore-fields and -output-base'() {
when:
def launcher = new Launcher().parseMainArgs('lineage','validate','lid://aaa','-against','lid://bbb','-ignore-fields','x,y','-output-base','/tmp/out')
then:
launcher.command instanceof CmdLineage
launcher.command.validateAgainst == 'lid://bbb'
launcher.command.validateIgnoreFields == 'x,y'
launcher.command.validateOutputBase == '/tmp/out'
}

def 'should return `run` command'() {
when:
def launcher = new Launcher().parseMainArgs('run','xxx', '-hub', 'bitbucket', '-user','xx:yy')
Expand Down
Loading
Loading