{"id":16964949,"url":"https://github.com/propensive/guillotine","last_synced_at":"2025-03-22T14:30:59.500Z","repository":{"id":47438533,"uuid":"126405228","full_name":"propensive/guillotine","owner":"propensive","description":"Making the execution of system processes easier in Scala","archived":false,"fork":false,"pushed_at":"2025-02-11T21:31:36.000Z","size":4179,"stargazers_count":13,"open_issues_count":3,"forks_count":3,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-03-18T11:52:02.670Z","etag":null,"topics":["exec","execution","process","scala","shell","system-processes"],"latest_commit_sha":null,"homepage":"https://soundness.dev/guillotine/","language":"Scala","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/propensive.png","metadata":{"files":{"readme":".github/readme.md","changelog":null,"contributing":".github/contributing.md","funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2018-03-22T23:07:24.000Z","updated_at":"2025-02-11T21:31:40.000Z","dependencies_parsed_at":"2024-04-12T20:25:35.387Z","dependency_job_id":"dd516d87-fba1-4974-8369-411e2a687bd5","html_url":"https://github.com/propensive/guillotine","commit_stats":null,"previous_names":[],"tags_count":21,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/propensive%2Fguillotine","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/propensive%2Fguillotine/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/propensive%2Fguillotine/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/propensive%2Fguillotine/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/propensive","download_url":"https://codeload.github.com/propensive/guillotine/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":244971766,"owners_count":20540850,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["exec","execution","process","scala","shell","system-processes"],"created_at":"2024-10-13T23:44:40.250Z","updated_at":"2025-03-22T14:30:59.492Z","avatar_url":"https://github.com/propensive.png","language":"Scala","funding_links":[],"categories":[],"sub_categories":[],"readme":"[\u003cimg alt=\"GitHub Workflow\" src=\"https://img.shields.io/github/actions/workflow/status/propensive/guillotine/main.yml?style=for-the-badge\" height=\"24\"\u003e](https://github.com/propensive/guillotine/actions)\n[\u003cimg src=\"https://img.shields.io/discord/633198088311537684?color=8899f7\u0026label=DISCORD\u0026style=for-the-badge\" height=\"24\"\u003e](https://discord.com/invite/MBUrkTgMnA)\n\u003cimg src=\"/doc/images/github.png\" valign=\"middle\"\u003e\n\n# Guillotine\n\n__A small library for executing stuff__\n\nGuillotine makes it easy to work with shell processes in Scala, with simple interpolation-based\ndefinitions of commands, and type-based interpretation of their output. For example, a directory\nlisting may be obtained with `sh\"ls $path\".exec[List[String]]()`.\n\n## Features\n\n- lightweight syntax for expressing shell commands, e.g. `sh\"ls\"`\n- typeclasses define how different types are substituted into commands\n- compile-time checking of command syntax, with correct handling of quotes and substitutions\n- typeclass-based execution strategies for commands\n- shell command results may be interpreted as `String`, `Int`, `Unit` or streamed as `LazyList`\n- processes may be started synchronously or asynchronously\n- commands may be piped to other commands with the `|` operator, or applied like functions\n\n\n## Availability\n\n\n\n\n\n\n\n## Getting Started\n\n### Commands\n\nShell commands are created using the `sh\"\"` interpolator, which will interpret (at compiletime) a\ncommand and its arguments, correctly interpreting single- and double-quoted arguments and escaped\ncharacters. Unclosed quotes will result in a compile error.\n\nSubstitutions of values of a variety of different types may be made into an `sh` interpolator, and\nmay be read as either \"single-argument\" (such as `String` or `Int`) or \"multi-argument\" (such as\n`List[Int]` or `Set[String]`).\n\nMulti-argument substitutions will be interpreted as multiple arguments to the shell command unless\nthey are enclosed within quotes, in which case they will be interpreted as a space-separated\nstring.\n\nSubstitutions should normally be surrounded by spaces, otherwise they will be prepended or appended\nto adjacent arguments.\n\n#### Piping\n\nTwo commands may be combined using the pipe operator (`|`), for example,\n```scala\nsh\"cat /home/work/file\" | sh\"grep $query\" | sh\"wc -l\"\n```\nwhich is equivalent to the single shell command, `cat /home/work/file | grep $query | wc -l`, with\nthe appropriate substitution of `query` being made.\n\nWhile this expression will seem very familiar from a shell-command perspective, it may also be\nwritten in function application style as,\n```scala\nsh\"wc -l\"(sh\"grep $query\"(sh\"cat /home/work/file\"))\n```\nand the two versions are equivalent.\n\n#### Substitutions\n\nSubstitutions of a variety of different types may be made into an interpolated `sh` command. Any\ntype for which a `gossamer.Show` typeclass exists will be inserted as a single parameter, and\nany sequence of one of these types will be inserted as multiple arguments. A `Command` instance\nmay also be substituted into another, for example,\n```scala\nval echo = sh\"echo Hello World\"\nsh\"sh -c '$echo'\"\n```\nwhere the quotes are required around `'$echo'` so that the command is passed to `sh -c` as a\nsingle argument, rather than multiple arguments (of which only the first would be used).\n\n#### Environment\n\nExecution requires an `Env` instance specifying a map of environment variables and a working\ndirectory as a `String`, and should be specified as a contextual value, for example,\n```scala\ngiven Env(Map(\"PATH\" -\u003e \"/usr/bin:/usr/sbin\"), \"/home/work\")\n```\nhowever it is common to use the `enclosing` environment. That is, to pass the environment in which\nthe JVM was started to its subprocess, ensuring that processes started by Guillotine behave as they\nwould if started directly from the shell. There may, however, be security implications when doing\nthis, so it must be explicitly enabled with:\n```scala\ngiven Env = envs.enclosing\n```\n\n### Execution\n\nTwo methods are provided for starting execution of a process: `fork` and `exec`, both taking a type\nparameter which determines the type of the return value, and may also affect how execution is\nhandled.\n\n```scala\nval result: String = sh\"echo Hello World\".exec[String]()\n```\n\nThe `exec` method will return a value synchronously, when that value is ready. This may happen only\nwhen the process completes execution, if the entire output is caputured, for example if the\nreturn-type is `String`, or may happen earlier if a streaming return type, such as\n`LazyList[String]`, is specified.\n\nThe `fork` method always starts the process asynchronously, and returns an instance of `Process[T]`,\nwhere `T` is the specified return type.\n\n```scala\nval process: Process[String] = sh\"locate lostfile\".fork[String]()\n```\n\n`Process` implements a few useful methods for working with a running process:\n\n - `await()` which waits until the process completes, and returns its result of type `T`\n - `abort()` which stopes execution, by delegating to Java's `Process#destroy`\n - `kill()` which stopes execution, by delegating to Java's `Process#destroyForcibly`\n - `pid` which returns a `Pid` instance representing the OS-dependent process ID\n - `stdout` and `stderr` methods for directly accessing the process's output streams; these methods\n   both take an integer parameter limiting the number of bytes that may be read from the stream,\n   defaulting to `10MB`\n - `stdin(in)` which accepts a stream of bytes (`LazyList[IArray[Byte]]`) as standard input to the\n   process\n\nThe synchronous `exec[T]()` method is always equivalent to `fork[T]().await()`.\n\n### Result interpretation\n\nDifferent shell processes may behave differently in how their results should be interpreted. Those\ndifferences include the interpretation of the exit status—where different nonzero codes may be\ninterpreted as different types of failure—and which stream contains the important output, `STDOUT`\nor `STDERR`.\n\nHow these differences are interpreted is determined by the choice of return type: nonzero return\ntypes may be presented as thrown exceptions, or interpreted as a different sort of \"success\".\nFurthermore, the return type will determine whether the result may be return before the shell\nprocess terminates, or whether (in the case of a streaming response) it may be returned earlier.\n\nThe `Executor[T]` typeclass provides support for producing different return types. Executors for\nthe following types are provided:\n- `String`, which interprets the response using the system encoding and returns a value after the\n  process terminates\n- `LazyList[String]`, which provides a stream of lines of text (without the newline character)\n- `LazyList[IArray[Byte]]`, which returns a stream of byte arrays\n- `Unit`, to be used when the result is not important\n- `ExitStatus`, an enumeration of `Ok` or `Fail(status)` where `status` is a nonzero positive\n  integer\n\nCustom executors may be provided by implementing the `Executor` trait with the single abstract\nmethod,\n```scala\ndef interpret(process: java.lang.Process): T\n```\nor by mapping across an existing `Executor`, for example,\n```scala\ngiven Executor[Int] = summon[Executor[String]].map(_.toInt)\n```\nsince all `Executor`s are functors.\n\n\n\n\n\n## Status\n\nGuillotine is classified as __maturescent__. For reference, Soundness projects are\ncategorized into one of the following five stability levels:\n\n- _embryonic_: for experimental or demonstrative purposes only, without any guarantees of longevity\n- _fledgling_: of proven utility, seeking contributions, but liable to significant redesigns\n- _maturescent_: major design decisions broady settled, seeking probatory adoption and refinement\n- _dependable_: production-ready, subject to controlled ongoing maintenance and enhancement; tagged as version `1.0.0` or later\n- _adamantine_: proven, reliable and production-ready, with no further breaking changes ever anticipated\n\nProjects at any stability level, even _embryonic_ projects, can still be used,\nas long as caution is taken to avoid a mismatch between the project's stability\nlevel and the required stability and maintainability of your own project.\n\nGuillotine is designed to be _small_. Its entire source code currently consists\nof 672 lines of code.\n\n## Building\n\nGuillotine will ultimately be built by Fury, when it is published. In the\nmeantime, two possibilities are offered, however they are acknowledged to be\nfragile, inadequately tested, and unsuitable for anything more than\nexperimentation. They are provided only for the necessity of providing _some_\nanswer to the question, \"how can I try Guillotine?\".\n\n1. *Copy the sources into your own project*\n   \n   Read the `fury` file in the repository root to understand Guillotine's build\n   structure, dependencies and source location; the file format should be short\n   and quite intuitive. Copy the sources into a source directory in your own\n   project, then repeat (recursively) for each of the dependencies.\n\n   The sources are compiled against the latest nightly release of Scala 3.\n   There should be no problem to compile the project together with all of its\n   dependencies in a single compilation.\n\n2. *Build with [Wrath](https://github.com/propensive/wrath/)*\n\n   Wrath is a bootstrapping script for building Guillotine and other projects in\n   the absence of a fully-featured build tool. It is designed to read the `fury`\n   file in the project directory, and produce a collection of JAR files which can\n   be added to a classpath, by compiling the project and all of its dependencies,\n   including the Scala compiler itself.\n   \n   Download the latest version of\n   [`wrath`](https://github.com/propensive/wrath/releases/latest), make it\n   executable, and add it to your path, for example by copying it to\n   `/usr/local/bin/`.\n\n   Clone this repository inside an empty directory, so that the build can\n   safely make clones of repositories it depends on as _peers_ of `guillotine`.\n   Run `wrath -F` in the repository root. This will download and compile the\n   latest version of Scala, as well as all of Guillotine's dependencies.\n\n   If the build was successful, the compiled JAR files can be found in the\n   `.wrath/dist` directory.\n\n## Contributing\n\nContributors to Guillotine are welcome and encouraged. New contributors may like\nto look for issues marked\n[beginner](https://github.com/propensive/guillotine/labels/beginner).\n\nWe suggest that all contributors read the [Contributing\nGuide](/contributing.md) to make the process of contributing to Guillotine\neasier.\n\nPlease __do not__ contact project maintainers privately with questions unless\nthere is a good reason to keep them private. While it can be tempting to\nrepsond to such questions, private answers cannot be shared with a wider\naudience, and it can result in duplication of effort.\n\n## Author\n\nGuillotine was designed and developed by Jon Pretty, and commercial support and\ntraining on all aspects of Scala 3 is available from [Propensive\nO\u0026Uuml;](https://propensive.com/).\n\n\n\n## Name\n\nGuillotine is named after the Eighteenth Century execution apparatus, as both perform executions.\n\nIn general, Soundness project names are always chosen with some rationale,\nhowever it is usually frivolous. Each name is chosen for more for its\n_uniqueness_ and _intrigue_ than its concision or catchiness, and there is no\nbias towards names with positive or \"nice\" meanings—since many of the libraries\nperform some quite unpleasant tasks.\n\nNames should be English words, though many are obscure or archaic, and it\nshould be noted how willingly English adopts foreign words. Names are generally\nof Greek or Latin origin, and have often arrived in English via a romance\nlanguage.\n\n## Logo\n\nThe logo shows the principal parts of a guillotine: the lunette and the blade.\n\n## License\n\nGuillotine is copyright \u0026copy; 2025 Jon Pretty \u0026 Propensive O\u0026Uuml;, and\nis made available under the [Apache 2.0 License](/license.md).\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpropensive%2Fguillotine","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fpropensive%2Fguillotine","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpropensive%2Fguillotine/lists"}