Git Product home page Git Product logo

playcli's Introduction

Play CLI

Play CLI defines helpers to deal with UNIX command with Play Framework iteratees.

Getting Started

Add this SBT dependency:

"fr.greweb" %% "playcli" % "0.12"

Play CLI depends only on play-iteratee.

Some random examples:

import playcli._
val logs = CLI.enumerate("tail -f aLogFile")
/* Ok.stream(logs) */

val colorQuantize = CLI.pipe("convert - -colors 14 png:-")
/* Ok.stream(anImageEnum &> colorQuantize) */

val scaleVideoHalf = CLI.pipe("ffmpeg -i pipe:0 -vf scale=iw/2:-1 -f avi pipe:1")
/* Ok.stream(streamEnum &> scaleVideoHalf) */

// Don't concatenate CMD string, but use the Seq syntax:
val logs = CLI.enumerate(Seq("tail", "-f", myFilePath))
/* Ok.stream(logs) */

// A consume example
val events : Enumerator[String] = …
events &> 
  Enumerator.map(e => (e+"\n").map(_.toByte).toArray) |>>> 
  CLI.consume("externalLoggerCmd")

// 

… continue to the scala API

playcli's People

Contributors

gre avatar yzernik avatar kompot avatar

Stargazers

曹文忠 avatar Ilgaz Şumnulu avatar  avatar  avatar Anton Karamanov avatar masahiroSkd avatar Toshiyuki Takahashi avatar  avatar  avatar Mehmet Ali avatar Hisham Mardam-Bey avatar Olivier Blanvillain avatar Vincent Jousse avatar Thomas Lockney avatar Janfy avatar SwhGo_oN avatar Tom avatar  avatar almoehi avatar nazoking avatar  avatar Rohit Rai avatar Daniel Trinh avatar Francis De Brabandere avatar Antoine Gourlay avatar Seth Tisue avatar Some Dude avatar  avatar Raúl Raja Martínez avatar Andy Kramolisch avatar Yvonnick Esnault avatar  avatar Leon Radley avatar Masion Frédéric avatar Vincent Debergue avatar Peter Rudenko avatar Mickaël Gauvin avatar  avatar  avatar Greg BOUGEARD avatar Dan Brown avatar Alexandre Tamborrino avatar Mikhail Trishchenkov avatar Daniel Westheide avatar Vladimir Adamić avatar Stéphane Le Dorze avatar Adrien Lavoillotte avatar Bastien Louërat avatar Piyush Purang avatar Mathieu ANCELIN avatar Steve Sowerby avatar Mathias Bogaert avatar  avatar Vicente Mendoza avatar Manuel Fuchs avatar  avatar Kumanan Rajamanikkam avatar Janko Boehme avatar Ludovic Claude avatar Spiros Tzavellas avatar Mike Li avatar Paolo de Dios avatar Sean Gao avatar Felix Geller avatar Federico Feroldi avatar benve avatar Age Mooij avatar Jonas Bonér avatar Tyler Weir avatar

Watchers

Sofiane Laouini avatar Choon Kee Oh avatar Franklin Chen avatar  avatar Mathias Bogaert avatar Rob Schellhorn avatar  avatar Mathieu ANCELIN avatar Stéphane Le Dorze avatar SwhGo_oN avatar James Cloos avatar Pawan Kumar avatar  avatar

playcli's Issues

Handle CLI errors (command not found kind)

I've started to implement it like this:

(pipe example)

  runProcess(command) map { case (process, stdin, stdout, stderr) =>
     ...
  } getOrElse(Future.successful(Error("CLI failed", Input.Empty)))

But it's maybe not the good way.

CLI.pipe not working with Enumerator.generateM

  import collection.immutable.StringOps
  import play.api.libs.concurrent.Promise.timeout
  import concurrent.{Await}
  import concurrent.duration.Duration
  val maxDuration = Duration.Inf
  val stringToBytes = (str: StringOps) => str.map(_.toByte).toArray
  val bytesJoinConsumer = Iteratee.fold[Array[Byte], Array[Byte]](Array[Byte]())((a, b) => a++b)
  val nbOfLines = 3
  val line = stringToBytes("hello\n")
  val enum = Enumerator.generateM[Array[Byte]] {
    timeout(Some(line), 5)
  }
  val pipe = CLI.pipe(Seq("head", "-n", nbOfLines.toString), 10)

  val result: Array[Byte] = Await.result(enum &> pipe |>>> bytesJoinConsumer, maxDuration)
  println(result.map(_.toChar).mkString)

It is not possible to grep tail command

Tail as an enumerator keeps waiting and does not go through grep. Below is a sample code to reproduce the issue.

val file = args(0)
val pattern = args(1)

val tail = CLI.enumerate(Seq("tail", "-f", file))
val grep = CLI.pipe(Seq("grep", pattern))
val printlnIteratee = Iteratee.foreach[Array[Byte]](s => print(new String(s)))

tail &> grep |>>> printlnIteratee

CLI.pipe issues

CLI.pipe current implementation seems to lock in some case (command are not closed and nothing is streamed anymore).

  1. when chaining multiple CLI.pipe.
  2. when triggering a lot of pipe (with the ffmpeg example and opening multiple connections).
  3. during some time (~ 2min in the webradio example)

Example for (1):

import concurrent.ExecutionContext.Implicits.global
import concurrent.{Future, Await}
import concurrent.duration.Duration
import play.api.libs.iteratee._
import cli.CLI

val enum = Enumerator("test".map(_.toByte).toArray)
val cat = CLI.pipe("cat")
val all = enum &> cat &> cat &> cat |>>> Iteratee.consume[Array[Byte]]()
concurrent.Await.result(all, Duration("2 s")).map(_.toChar).mkString

CLI.pipe lock issue with `convert`

Example: CLI.pipe("convert - png:-")

Bug: the command is never terminated. stdin is written, but nothing is read from the command which is not responding.

Make broadcast working

Exemple:

val addEchoToOgg = CLI.pipe("sox -t ogg - -t ogg - echo 0.5 0.7 60 1")
val radioStream = proxyBroadcast("http://radio.hbr1.com:19800/ambient.ogg")
val (radioStreamWithEcho, _) = Concurrent.broadcast(radioStream &> addEchoToOgg)

def radio = Action(Ok.stream(radioStreamWithEcho).withHeaders(CONTENT_TYPE -> "audio/ogg"))

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.