Skip to content

Instantly share code, notes, and snippets.

@tynanbe
Created January 26, 2021 19:00
Show Gist options
  • Save tynanbe/7f5fa408bc33f562361f3ab30665d276 to your computer and use it in GitHub Desktop.
Save tynanbe/7f5fa408bc33f562361f3ab30665d276 to your computer and use it in GitHub Desktop.
Local example: gleam docs publish --version 0.1.0
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width" />
<title>shellout - shellout</title>
<link rel="stylesheet" href="../index.css" type="text/css" />
<!-- The docs_config.js file is provided by HexDocs and shared
between multiple versions of the same package. -->
<script src="../docs_config.js"></script>
</head>
<body>
<header class="page-header">
<h2>
shellout
<span id="project-version"> - v0.1.0 </span>
</h2>
</header>
<div class="page">
<nav class="sidebar">
<a class="sidebar-toggle" href="#" tabindex="0">
<svg
aria-hidden="true"
focusable="false"
data-prefix="fas"
data-icon="bars"
class="svg-inline--fa fa-bars fa-w-14"
role="img"
xmlns="http://www.w3.org/2000/svg"
viewBox="0 0 448 512"
>
<path
fill="#fff"
d="M16 132h416c8.837 0 16-7.163 16-16V76c0-8.837-7.163-16-16-16H16C7.163 60 0 67.163 0 76v40c0 8.837 7.163 16 16 16zm0 160h416c8.837 0 16-7.163 16-16v-40c0-8.837-7.163-16-16-16H16c-8.837 0-16 7.163-16 16v40c0 8.837 7.163 16 16 16zm0 160h416c8.837 0 16-7.163 16-16v-40c0-8.837-7.163-16-16-16H16c-8.837 0-16 7.163-16 16v40c0 8.837 7.163 16 16 16z"
>
</path>
</svg>
</a>
<h2>Pages</h2>
<ul>
<li><a href="../index.html">README</a></li>
</ul>
<h2>Modules</h2>
<ul>
<li><a href="../shellout&#x2f;">shellout</a></li>
</ul>
<h2>Types</h2>
<ul>
<li><a href="#CmdOpt">CmdOpt</a></li>
<li><a href="#CmdResult">CmdResult</a></li>
</ul>
<h2>Functions</h2>
<ul>
<li><a href="#cmd">cmd</a></li>
</ul>
</nav>
<main class="content">
<h1 class="module-name">shellout</h1>
<p>A Gleam wrapper for <a href="https://hexdocs.pm/elixir/master/System.html#cmd/3"><code>Elixir.System.cmd/3</code></a></p>
<section class="module-members">
<a href="#module-types">
<h1 id="module-types" class="module-member-kind">Types</h1>
</a>
<div class="member">
<div class="member-name">
<h2 id="CmdOpt">
<a href="#CmdOpt">
CmdOpt
</a>
</h2>
<a href="https://github.com/tynanbe/shellout/blob/v0.1.0/src/shellout.gleam#L11-L11">
&lt;/&gt;
</a>
</div>
<div class="custom-type-constructors">
<div class="rendered-markdown"></div>
<pre>pub type CmdOpt {
Into(List(Nil))
Cd(String)
Env(List(tuple(String, String)))
Arg0(String)
StderrToStdout(Bool)
Parallelism(Bool)
}</pre>
<h3>
Constructors
</h3>
<ul>
<li>
<code class="constructor-name">Into(List(Nil))</code>
</li>
<li>
<code class="constructor-name">Cd(String)</code>
</li>
<li>
<code class="constructor-name">Env(List(tuple(String, String)))</code>
</li>
<li>
<code class="constructor-name">Arg0(String)</code>
</li>
<li>
<code class="constructor-name">StderrToStdout(Bool)</code>
</li>
<li>
<code class="constructor-name">Parallelism(Bool)</code>
</li>
</ul>
</div>
</div>
<div class="member">
<div class="member-name">
<h2 id="CmdResult">
<a href="#CmdResult">
CmdResult
</a>
</h2>
<a href="https://github.com/tynanbe/shellout/blob/v0.1.0/src/shellout.gleam#L20-L21">
&lt;/&gt;
</a>
</div>
<div class="custom-type-constructors">
<div class="rendered-markdown"></div>
<pre>pub type CmdResult =
Result(tuple(List(String), Int), String)</pre>
</div>
</div>
</section>
<section class="module-members">
<a href="#module-functions">
<h1 id="module-functions" class="module-member-kind">Functions</h1>
</a>
<div class="member">
<div class="member-name">
<h2 id="cmd">
<a href="#cmd">
cmd
</a>
</h2>
<a href="https://github.com/tynanbe/shellout/blob/v0.1.0/src/shellout.gleam#L69-L73">
&lt;/&gt;
</a>
</div>
<pre>pub fn cmd(
bin command: String,
args args: List(String),
opts opts: List(CmdOpt),
) -&gt; Result(tuple(List(String), Int), String)</pre>
<div class="rendered-markdown"><p>Executes the given <code>command</code> with <code>args</code>.</p>
<p><code>command</code> is expected to be an executable available in PATH unless an
absolute path is given.</p>
<p><code>args</code> must be a <code>List(String)</code> which the executable will receive as its
arguments as is. This means that:</p>
<ul>
<li>environment variables will not be interpolated</li>
<li>wildcard expansion will not happen</li>
<li>arguments do not need to be escaped or quoted for shell safety</li>
</ul>
<p>This function returns a <code>Result</code>, where <code>success</code> is a
<code>tuple(List(String), Int)</code> containing a <code>List</code> of lines collected from
stdout, and the command exit status.</p>
<h2>Examples</h2>
<pre><code>&gt; shellout.cmd(&quot;printf&quot;, [&quot;%s\n&quot;, &quot;hi&quot;], [])
Ok(tuple([&quot;hi\n&quot;], 0))
&gt; let options = [Env([tuple(&quot;MIX_ENV&quot;, &quot;test&quot;)])]
&gt; shellout.cmd(&quot;printf&quot;, [&quot;%s\n&quot;, &quot;hi&quot;], options)
Ok(tuple([&quot;hi\n&quot;], 0))
&gt; shellout.cmd(&quot;&quot;, [], [StderrToStdout(True)])
Error(&quot;Error: Could not execute ``\n`` does not exist&quot;)
</code></pre>
<h2>Options</h2>
<ul>
<li><code>Cd(String)</code> - the directory to run the command in</li>
<li><code>Env(List(tuple(String, String)))</code> - Tuples contain environment key-value
<code>String</code>s. The child process inherits all environment variables from its
parent process, the Gleam application, except those overwritten or cleared
using this option. Specify a value of <code>Nil</code> to clear (unset) an environment
variable, which is useful for preventing credentials passed to the
application from leaking into child processes.</li>
<li><code>Arg0(String)</code> - sets the command arg0</li>
<li><code>StderrToStdout(Bool)</code> - redirects stderr to stdout when <code>True</code></li>
<li><code>Parallelism(Bool)</code> - when <code>True</code>, the VM will schedule port tasks to
improve parallelism in the system. If set to <code>False</code>, the VM will try to
perform commands immediately, improving latency at the expense of
parallelism. The default can be set on system startup by passing the &quot;+spp&quot;
argument to <code>--erl</code>.</li>
</ul>
<p><em>Documentation adapted from <a href="https://hexdocs.pm/elixir/master/System.html#cmd/3"><code>Elixir.System.cmd/3</code></a></em></p>
</div>
</div>
</section>
</main>
</div>
<script>const pride = () => document.querySelector('body').classList.toggle('show-pride')</script>
<a class="pride-button" onclick="pride()">✨</a>
<footer class="pride" onclick="pride()">
<div class="blue">Lucy</div>
<div class="pink">says</div>
<div class="white">trans</div>
<div class="pink">rights</div>
<div class="blue">✨</div>
</footer>
<script>
if (typeof versionNodes !== 'undefined') {
const versionElement = document.getElementById('project-version')
const currentVersion = "v0.1.0"
if (!versionNodes.find(element => element.version === currentVersion)) {
versionNodes.unshift({ version: currentVersion, url: '#' })
}
const versionsDropdown = `
<form autocomplete="off">
<select onchange="window.location.href = this.value">
${versionNodes.map(element =>
`
<option value="${element.url}" ${element.version === currentVersion ? "selected disabled" : ""}>
${element.version}
</option>
`
).join('')}
</select>
</form>
`
versionElement.innerHTML = versionsDropdown
}
</script>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment