1
1
mirror of https://github.com/mcuadros/ascode synced 2025-02-20 00:21:10 +01:00
ascode/docs/reference/os/index.html

19 lines
13 KiB
HTML

<!doctype html><html lang=en><head><meta charset=utf-8><meta http-equiv=x-ua-compatible content="ie=edge"><title>os - AsCode - Terraform Alternative Syntax</title><meta name=viewport content="width=device-width,initial-scale=1"><link rel=icon href=https://ascode.run/images/favicon.png><link rel=stylesheet href=/css/style.min.df49831c6872564dff31a5f0978a9571f2c8110b513d4b3b1fc8ead41dcdc9f0.css></head><body class="page page-default-single"><div id=main-menu-mobile class=main-menu-mobile><ul><li class=menu-item-home><a href=/><span>Home</span></a></li><li class=menu-item-docs><a href=/docs/><span>Docs</span></a></li><li class=menu-item-github><a href=https://github.com/mcuadros/ascode><span>GitHub</span></a></li></ul></div><div class=wrapper><div class=header><div class=container><div class=logo><a href=https://ascode.run><img alt=Logo src=/images/logo-header.svg></a></div><div class=logo-mobile><a href=https://ascode.run><img alt=Logo src=/images/logo-header.svg></a></div><div id=main-menu class=main-menu><ul><li class=menu-item-home><a href=/><span>Home</span></a></li><li class=menu-item-docs><a href=/docs/><span>Docs</span></a></li><li class=menu-item-github><a href=https://github.com/mcuadros/ascode><span>GitHub</span></a></li></ul></div><button id=toggle-main-menu-mobile class="hamburger hamburger--slider" type=button>
<span class=hamburger-box><span class=hamburger-inner></span></span></button></div></div><div class="main container pt-2 pt-md-6 pb-3 pb-md-6"><div class=row><div class="col-12 col-md-3 mb-3"><div class=sidebar><div class=docs-menu><h4><a href=/docs/reference/>API Reference</a></h4><ul><li><a href=/docs/reference/types/>built-in</a></li><li><a href=/docs/reference/docker/>docker</a></li><li><a href=/docs/reference/base64/>encoding/base64</a></li><li><a href=/docs/reference/csv/>encoding/csv</a></li><li><a href=/docs/reference/json/>encoding/json</a></li><li><a href=/docs/reference/yaml/>encoding/yaml</a></li><li><a href=/docs/reference/http/>http</a></li><li><a href=/docs/reference/math/>math</a></li><li><a class=active href=/docs/reference/os/>os</a></li><li><a href=/docs/reference/filepath/>path/filepath</a></li><li><a href=/docs/reference/re/>re</a></li><li><a href=/docs/reference/time/>time</a></li><li><a href=/docs/reference/url/>url</a></li></ul></div><div style=font-size:90%;margin-top:40px><a href=/docs/>« Documentation</a></div></div></div><div class="col-12 col-md-9"><h1 class=title>os</h1><div class=content><h2 id=index>Index</h2><div class=toc><nav id=TableOfContents><ul><li><a href=#overview>Overview</a></li><li><a href=#functions>Functions</a><ul><li><a href=#def-bchdirb>def <b>chdir</b></a></li><li><a href=#def-bcommandb>def <b>command</b></a></li><li><a href=#def-bgetenvb>def <b>getenv</b></a></li><li><a href=#def-bgetwdb>def <b>getwd</b></a></li><li><a href=#def-bmkdirb>def <b>mkdir</b></a></li><li><a href=#def-bmkdir_allb>def <b>mkdir_all</b></a></li><li><a href=#def-bread_fileb>def <b>read_file</b></a></li><li><a href=#def-bremoveb>def <b>remove</b></a></li><li><a href=#def-bremove_allb>def <b>remove_all</b></a></li><li><a href=#def-brenameb>def <b>rename</b></a></li><li><a href=#def-bsetenvb>def <b>setenv</b></a></li><li><a href=#def-btemp_dirb>def <b>temp_dir</b></a></li><li><a href=#def-bwrite_fileb>def <b>write_file</b></a></li></ul></li></ul></nav></div><h2 id=overview>Overview</h2><p>os provides a platform-independent interface to operating system functionality.</p><h2 id=functions>Functions</h2><h3 id=def-bchdirb>def <b>chdir</b></h3><div class=highlight><pre class=chroma><code class=language-go data-lang=go><span class=nf>chdir</span><span class=p>(</span><span class=nx>dir</span><span class=p>)</span>
</code></pre></div><p>changes the current working directory to the named directory.</p><h6 id=arguments>Arguments</h6><table><thead><tr><th>name</th><th>type</th><th>description</th></tr></thead><tbody><tr><td><code>dir</code></td><td><code>string</code></td><td>target dir</td></tr></tbody></table><h3 id=def-bcommandb>def <b>command</b></h3><div class=highlight><pre class=chroma><code class=language-go data-lang=go><span class=nf>command</span><span class=p>(</span><span class=nx>command</span><span class=p>,</span> <span class=nx>shell</span><span class=p>=</span><span class=nx>False</span><span class=p>,</span> <span class=nx>dir</span><span class=p>=</span><span class=s>&#34;&#34;</span><span class=p>,</span> <span class=nx>combined</span><span class=p>=</span><span class=nx>False</span><span class=p>,</span> <span class=nx>env</span><span class=p>=[])</span>
</code></pre></div><p>runs the command and returns its standard output. If the exit code
it different to zero, an error is triggered.</p><h6 id=arguments-1>Arguments</h6><table><thead><tr><th>name</th><th>type</th><th>description</th></tr></thead><tbody><tr><td><code>shell</code></td><td><code>bool</code></td><td>if True execute the command inside of a shell.</td></tr><tr><td><code>dir</code></td><td><code>string</code></td><td>working directory of the command.</td></tr><tr><td><code>combined</code></td><td><code>bool</code></td><td>if True returns combined standard output and standard error.</td></tr><tr><td><code>env</code></td><td><code>list</code></td><td>specifies the environment of the process, each value of the listshould follow the pattern &ldquo;key=value&rdquo;.</td></tr></tbody></table><h3 id=def-bgetenvb>def <b>getenv</b></h3><div class=highlight><pre class=chroma><code class=language-go data-lang=go><span class=nf>getenv</span><span class=p>(</span><span class=nx>key</span><span class=p>)</span> <span class=nx>dir</span>
</code></pre></div><p>retrieves the value of the environment variable named by the key.</p><h6 id=arguments-2>Arguments</h6><table><thead><tr><th>name</th><th>type</th><th>description</th></tr></thead><tbody><tr><td><code>key</code></td><td><code>string</code></td><td>name of the environment variable</td></tr></tbody></table><h3 id=def-bgetwdb>def <b>getwd</b></h3><div class=highlight><pre class=chroma><code class=language-go data-lang=go><span class=nf>getwd</span><span class=p>()</span> <span class=nx>dir</span>
</code></pre></div><p>returns a rooted path name corresponding to the current directory.</p><h3 id=def-bmkdirb>def <b>mkdir</b></h3><div class=highlight><pre class=chroma><code class=language-go data-lang=go><span class=nf>mkdir</span><span class=p>(</span><span class=nx>name</span><span class=p>,</span> <span class=nx>perms</span><span class=p>=</span><span class=mi>0</span><span class=nx>o777</span><span class=p>)</span>
</code></pre></div><p>creates a new directory with the specified name and permission bits (before umask).</p><h6 id=arguments-3>Arguments</h6><table><thead><tr><th>name</th><th>type</th><th>description</th></tr></thead><tbody><tr><td><code>name</code></td><td><code>string</code></td><td>name of the folder to be created</td></tr><tr><td><code>perms</code></td><td><code>int</code></td><td>optional, permission of the folder</td></tr></tbody></table><h3 id=def-bmkdir_allb>def <b>mkdir_all</b></h3><div class=highlight><pre class=chroma><code class=language-go data-lang=go><span class=nf>mkdir_all</span><span class=p>(</span><span class=nx>name</span><span class=p>,</span> <span class=nx>perms</span><span class=p>=</span><span class=mi>0</span><span class=nx>o777</span><span class=p>)</span>
</code></pre></div><p>creates a new directory with the specified name and permission bits (before umask).</p><h6 id=arguments-4>Arguments</h6><table><thead><tr><th>name</th><th>type</th><th>description</th></tr></thead><tbody><tr><td><code>name</code></td><td><code>string</code></td><td>name of the folder to be created</td></tr><tr><td><code>perms</code></td><td><code>int</code></td><td>optional, permission of the folder</td></tr></tbody></table><h3 id=def-bread_fileb>def <b>read_file</b></h3><div class=highlight><pre class=chroma><code class=language-go data-lang=go><span class=nf>read_file</span><span class=p>(</span><span class=nx>filename</span><span class=p>)</span> <span class=kt>string</span>
</code></pre></div><p>reads the file named by filename and returns the contents.</p><h6 id=arguments-5>Arguments</h6><table><thead><tr><th>name</th><th>type</th><th>description</th></tr></thead><tbody><tr><td><code>filename</code></td><td><code>string</code></td><td>name of the file to be written</td></tr><tr><td><code>data</code></td><td><code>string</code></td><td>content to be witten to the file</td></tr><tr><td><code>perms</code></td><td><code>int</code></td><td>optional, permission of the file</td></tr></tbody></table><h3 id=def-bremoveb>def <b>remove</b></h3><div class=highlight><pre class=chroma><code class=language-go data-lang=go><span class=nf>remove</span><span class=p>(</span><span class=nx>name</span><span class=p>)</span>
</code></pre></div><p>removes the named file or (empty) directory.</p><h6 id=arguments-6>Arguments</h6><table><thead><tr><th>name</th><th>type</th><th>description</th></tr></thead><tbody><tr><td><code>name</code></td><td><code>string</code></td><td>name of the file or directory to be deleted</td></tr></tbody></table><h3 id=def-bremove_allb>def <b>remove_all</b></h3><div class=highlight><pre class=chroma><code class=language-go data-lang=go><span class=nf>remove_all</span><span class=p>(</span><span class=nx>path</span><span class=p>)</span>
</code></pre></div><p>removes path and any children it contains. It removes everything it
can but returns the first error it encounters.</p><h6 id=arguments-7>Arguments</h6><table><thead><tr><th>name</th><th>type</th><th>description</th></tr></thead><tbody><tr><td><code>name</code></td><td><code>string</code></td><td>path to be deleted</td></tr></tbody></table><h3 id=def-brenameb>def <b>rename</b></h3><div class=highlight><pre class=chroma><code class=language-go data-lang=go><span class=nf>rename</span><span class=p>(</span><span class=nx>oldpath</span><span class=p>,</span> <span class=nx>newpath</span><span class=p>)</span>
</code></pre></div><p>renames (moves) oldpath to newpath. If newpath already exists and is
not a directory, Rename replaces it. OS-specific restrictions may
apply when oldpath and newpath are in different directories.</p><h6 id=arguments-8>Arguments</h6><table><thead><tr><th>name</th><th>type</th><th>description</th></tr></thead><tbody><tr><td><code>oldpath</code></td><td><code>string</code></td><td>old path</td></tr><tr><td><code>newpath</code></td><td><code>string</code></td><td>new path</td></tr></tbody></table><h3 id=def-bsetenvb>def <b>setenv</b></h3><div class=highlight><pre class=chroma><code class=language-go data-lang=go><span class=nf>setenv</span><span class=p>(</span><span class=nx>key</span><span class=p>,</span> <span class=nx>value</span><span class=p>)</span> <span class=nx>dir</span>
</code></pre></div><p>sets the value of the environment variable named by the key.</p><h6 id=arguments-9>Arguments</h6><table><thead><tr><th>name</th><th>type</th><th>description</th></tr></thead><tbody><tr><td><code>key</code></td><td><code>string</code></td><td>name of the environment variable</td></tr><tr><td><code>value</code></td><td><code>string</code></td><td>value of the environment variable</td></tr></tbody></table><h3 id=def-btemp_dirb>def <b>temp_dir</b></h3><div class=highlight><pre class=chroma><code class=language-go data-lang=go><span class=nf>temp_dir</span><span class=p>()</span>
</code></pre></div><p>returns the default directory to use for temporary files.</p><h3 id=def-bwrite_fileb>def <b>write_file</b></h3><div class=highlight><pre class=chroma><code class=language-go data-lang=go><span class=nf>write_file</span><span class=p>(</span><span class=nx>filename</span><span class=p>,</span> <span class=nx>data</span><span class=p>,</span> <span class=nx>perms</span><span class=p>=</span><span class=mi>0</span><span class=nx>o644</span><span class=p>)</span>
</code></pre></div><p>retrieves the value of the environment variable named by the key.</p><h6 id=arguments-10>Arguments</h6><table><thead><tr><th>name</th><th>type</th><th>description</th></tr></thead><tbody><tr><td><code>filename</code></td><td><code>string</code></td><td>name of the file to be written</td></tr><tr><td><code>data</code></td><td><code>string</code></td><td>content to be witten to the file</td></tr><tr><td><code>perms</code></td><td><code>int</code></td><td>optional, permission of the file</td></tr></tbody></table></div></div></div></div></div></div><div class=sub-footer><div class=container><div class=row><div class=col-12><div class=sub-footer-inner><ul><li><a href=https://github.com/mcuadros/ascod>Documentation version v1.3.0</a></li><li>Template by <a href=https://www.zerostatic.io>Robert Austin</a></li></ul></div></div></div></div><script type=text/javascript src=/js/scripts.min.be6fe1294698d6acd837c5182149cd1a24daae9fa1903ce810c264539d254d62.js></script></body></html>