inoas / shellout

🐒 A Gleam library for cross-platform shell operations

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

shellout 🐒

Hex Package Hex Docs License Build

A Gleam library for cross-platform shell operations.


Usage

Example

β€’ In my_project/src/my_project.gleam

import gleam/io
import gleam/map
import shellout.{Lookups}

pub const lookups: Lookups = [
  #(
    ["color", "background"],
    [
      #("buttercup", ["252", "226", "174"]),
      #("mint", ["182", "255", "234"]),
      #("pink", ["255", "175", "243"]),
    ],
  ),
]

pub fn main() {
  let result =
    shellout.arguments()
    |> shellout.command(run: "ls", in: ".", opt: [])

  case result {
    Ok(output) -> {
      io.print(output)
      0
    }
    Error(#(status, message)) -> {
      message
      |> shellout.style(
        with: shellout.display(["bold", "italic"])
        |> map.merge(shellout.color(["pink"]))
        |> map.merge(shellout.background(["brightblack"])),
        custom: lookups,
      )
      |> io.print
      status
    }
  }
  |> shellout.exit
}

🐚 You can test the above example with your shell!

β€’ In your terminal

> cd my_project
> gleam run -- -lah
# ..
> gleam run -- --lah
# ..
> gleam run --target=javascript -- -lah
# ..
> gleam run --target=javascript -- --lah
# ..

Installation

As a dependency of your Gleam project

β€’ Add shellout to gleam.toml

[dependencies]
shellout = "~> 1.3"

As a dependency of your Mix project

β€’ Add shellout to mix.exs

defp deps do
  [
    {:shellout, "~> 1.3"},
  ]
end

As a dependency of your Rebar3 project

β€’ Add shellout to rebar.config

{deps, [
  {shellout, "1.3.0"}
]}.

About

🐒 A Gleam library for cross-platform shell operations

License:Apache License 2.0


Languages

Language:Gleam 60.6%Language:Erlang 14.3%Language:JavaScript 13.5%Language:TypeScript 11.6%