#!/usr/bin/env Rscript
## Copyright 2014, Sahil Seth
## licence: MIT
## sahil.seth@me.com
## A few functions to supplement those already in this package.
## URL: github.com/sahilseth/funr
#### -----------------------


## One may define their own functions here
## or load default packages they use quite often
## for example load devtools, knitr etc.



help_text = "

Usage: flowr function [arguments]

  status          Detailed status of a flow(s).
  rerun           rerun a previously failed flow
  kill            Kill the flow, upon providing working directory
  fetch_pipes     Checking what modules and pipelines are available; flowr fetch_pipes

Please use 'flowr -h function' to obtain further information about the usage.


Examples:
## Run a small pipeline
flowr run x=sleep_pipe platform=local
flowr run x=sleep_pipe platform=local execute=TRUE

## When running a pipeline, flowr create a unique working 
## directory for each flow. This is used to monitor, kill and re-run the flow.
wd=<path to a flowr execution folder>

## get status on all the run 
## (all flows with 'sleep_pipe' in their name are checked and their status is shown)
flowr status x=~/flowr/runs/sleep_pipe*
## Use parent folder to get summary of all the runs
flowr status x=~/flowr/runs

## kill the flow
flowr kill x=~/flowr/runs/sleep_pipe*
## if their are multiple flows, need to to be sure
flowr kill x=~/flowr/runs/sleep_pipe* force=TRUE

## using a FULL path to a execution folder
flowr rerun x=~/flowr/runs/sleep_pipe-samp1-20150921-11-51-31-F3VftKBp rerun=start_from
"

## parse all the arugment using the funr function
if(!require(funr)) install.packages('funr'); library(funr)
suppressMessages(library(flowr, verbose = FALSE, quietly = TRUE))
out = funr(args = commandArgs(trailingOnly = TRUE), script_name = "flowr", help_text = help_text)
## parse the output nicely using render_funr
funr::render_funr(out)

