aboutsummaryrefslogblamecommitdiff
path: root/commando/src/Main.scala
blob: 043a9f25a214322e43f26873b87c33fc6d95bcdc (plain) (tree)
1
2
3
4
5
6
7
8
9



                         

                                              
                                       
                                         
 
                         
                                                                











                                                        


                                                                                               
                                          
 



                                     








                         
package example

object Main extends App {

  val cmd = new commando.Command("xorc", "") {

    val version = named("version", 'V')
      .action(() => println("version 1"))

    named("verbose", 'v')
      .info("Set verbosity level. This option may be repeated.")
      .optionalArg("level")
      .action(level => println(s"level $level"))

    positional("FILES")
      .action { s =>
        val f = new java.io.File(s)
        if (!f.exists()) error(s"File $s does not exit")
        println(f)
      }
      .repeat()

    val comp = named("completion")
      .info(
        s"Print bash completion. Add  ${name} --completions to your bashrc to get completions."
      )
      .action(() => println(completion()))

    named("help", 'h')
      .info("print a help message")
      .action(() => println(usage()))

  }
  cmd.parse(args) match {
    case None =>
    case Some(error) =>
      println(error)
      sys.exit(1)
  }

}