nextflow.util.CmdLineHelper.groovy Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of nxf-commons Show documentation
Show all versions of nxf-commons Show documentation
A DSL modelled around the UNIX pipe concept, that simplifies writing parallel and scalable pipelines in a portable manner
/*
* Copyright (c) 2013-2016, Centre for Genomic Regulation (CRG).
* Copyright (c) 2013-2016, Paolo Di Tommaso and the respective authors.
*
* This file is part of 'Nextflow'.
*
* Nextflow is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Nextflow is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with Nextflow. If not, see .
*/
package nextflow.util
/**
*
* @author Paolo Di Tommaso
*/
class CmdLineHelper {
def List args
CmdLineHelper( String cmdLineToBeParsed ) {
args = splitter(cmdLineToBeParsed ?: '')
}
def boolean contains(String argument) {
return args.indexOf(argument) != -1
}
def getArg( String argument ) {
def pos = args.indexOf(argument)
if( pos == -1 ) return null
def result = []
for( int i=pos+1; i
* For example the string: {@code "alpha beta 'delta gamma'"} will return the following result
* {@code ["alpha", "beta", "delta gamma"]}
*
* @param cmdline The string to be splitted in single elements
* @return A list of string on which each entry represent a command line argument, or an
* empty list if the {@code cmdline} parameter is empty
*/
static List splitter( String cmdline ) {
List result = []
if( cmdline ) {
QuoteStringTokenizer tokenizer = new QuoteStringTokenizer(cmdline);
while( tokenizer.hasNext() ) {
result.add(tokenizer.next())
}
}
result
}
static String toLine( String... args ) {
toLine( args as List)
}
static String toLine( List args ) {
def result = new ArrayList(args.size())
args.each { result << (it.contains(' ') ? "'${it}'" : it) }
return result.join(' ')
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy