2022-01-13 23:27:39 +01:00
|
|
|
package obioptions
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
"os"
|
2022-01-14 23:11:36 +01:00
|
|
|
"runtime"
|
2022-01-13 23:27:39 +01:00
|
|
|
|
|
|
|
"github.com/DavidGamba/go-getoptions"
|
|
|
|
)
|
|
|
|
|
2022-01-14 23:11:36 +01:00
|
|
|
var _Debug = false
|
|
|
|
var _ParallelWorkers = runtime.NumCPU() - 1
|
|
|
|
var _BufferSize = 1
|
|
|
|
var _BatchSize = 5000
|
2022-01-13 23:27:39 +01:00
|
|
|
|
|
|
|
type ArgumentParser func([]string) (*getoptions.GetOpt, []string, error)
|
|
|
|
|
|
|
|
func GenerateOptionParser(optionset ...func(*getoptions.GetOpt)) ArgumentParser {
|
|
|
|
options := getoptions.New()
|
|
|
|
options.Bool("help", false, options.Alias("h", "?"))
|
2022-01-14 23:11:36 +01:00
|
|
|
options.BoolVar(&_Debug, "debug", false)
|
|
|
|
|
|
|
|
options.IntVar(&_ParallelWorkers, "workers", runtime.NumCPU()-1,
|
|
|
|
options.Alias("w"),
|
|
|
|
options.Description("Number of parallele threads computing the result"))
|
2022-01-13 23:27:39 +01:00
|
|
|
|
|
|
|
for _, o := range optionset {
|
|
|
|
o(options)
|
|
|
|
}
|
|
|
|
|
|
|
|
return func(args []string) (*getoptions.GetOpt, []string, error) {
|
|
|
|
|
|
|
|
remaining, err := options.Parse(args[1:])
|
|
|
|
|
|
|
|
if options.Called("help") {
|
2022-01-14 16:10:19 +01:00
|
|
|
fmt.Fprint(os.Stderr, options.Help())
|
2022-01-13 23:27:39 +01:00
|
|
|
os.Exit(1)
|
|
|
|
}
|
|
|
|
return options, remaining, err
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-01-14 23:11:36 +01:00
|
|
|
// Predicate indicating if the debug mode is activated.
|
2022-02-01 17:31:28 +01:00
|
|
|
func CLIIsDebugMode() bool {
|
2022-01-14 23:11:36 +01:00
|
|
|
return _Debug
|
|
|
|
}
|
|
|
|
|
2022-02-01 17:31:28 +01:00
|
|
|
// CLIParallelWorkers returns the number of parallel workers requested by
|
2022-01-14 23:11:36 +01:00
|
|
|
// the command line option --workers|-w.
|
2022-02-01 17:31:28 +01:00
|
|
|
func CLIParallelWorkers() int {
|
2022-01-14 23:11:36 +01:00
|
|
|
return _ParallelWorkers
|
|
|
|
}
|
|
|
|
|
2022-02-01 17:31:28 +01:00
|
|
|
// CLIBufferSize returns the expeted channel buffer size for obitools
|
|
|
|
func CLIBufferSize() int {
|
2022-01-14 23:11:36 +01:00
|
|
|
return _BufferSize
|
|
|
|
}
|
|
|
|
|
2022-02-01 17:31:28 +01:00
|
|
|
// CLIBatchSize returns the expeted size of the sequence batches
|
|
|
|
func CLIBatchSize() int {
|
2022-01-14 23:11:36 +01:00
|
|
|
return _BatchSize
|
2022-01-13 23:27:39 +01:00
|
|
|
}
|
|
|
|
|
2022-01-14 23:11:36 +01:00
|
|
|
// DebugOn sets the debug mode on.
|
2022-01-13 23:27:39 +01:00
|
|
|
func DebugOn() {
|
2022-01-14 23:11:36 +01:00
|
|
|
_Debug = true
|
2022-01-13 23:27:39 +01:00
|
|
|
}
|
|
|
|
|
2022-01-14 23:11:36 +01:00
|
|
|
// DebugOff sets the debug mode off.
|
2022-01-13 23:27:39 +01:00
|
|
|
func DebugOff() {
|
2022-01-14 23:11:36 +01:00
|
|
|
_Debug = false
|
2022-01-13 23:27:39 +01:00
|
|
|
}
|