shell snippet fixes, nextjs-scripts upgrades

This commit is contained in:
Jeff Escalante 2020-05-29 17:12:05 -04:00
parent 87f38e84ef
commit 66c34f5110
No known key found for this signature in database
GPG Key ID: 32D23C61AB5450DB
131 changed files with 707 additions and 816 deletions

4
website/.stylelintrc.js Normal file
View File

@ -0,0 +1,4 @@
module.exports = {
...require('@hashicorp/nextjs-scripts/.stylelintrc.js'),
/* Specify overrides here */
}

View File

@ -1,5 +1,5 @@
import Subnav from '@hashicorp/react-subnav' import Subnav from '@hashicorp/react-subnav'
import subnavItems from '../../data/subnav' import subnavItems from 'data/subnav'
import { useRouter } from 'next/router' import { useRouter } from 'next/router'
export default function PackerSubnav() { export default function PackerSubnav() {

5
website/jsconfig.json Normal file
View File

@ -0,0 +1,5 @@
{
"compilerOptions": {
"baseUrl": "."
}
}

View File

@ -1,18 +0,0 @@
import React from 'react'
import Bugsnag from '@bugsnag/js'
import BugsnagReact from '@bugsnag/plugin-react'
const apiKey =
typeof window === 'undefined'
? 'b6c57b27a37e531a5de94f065dd98bc0'
: 'de0b822b269aa57b620efd8927e03744'
if (!Bugsnag._client) {
Bugsnag.start({
apiKey,
plugins: [new BugsnagReact(React)],
otherOptions: { releaseStage: process.env.NODE_ENV || 'development' },
})
}
export default Bugsnag

View File

@ -1,76 +0,0 @@
const isProd = process.env.NODE_ENV === 'production'
const segmentWriteKey = isProd
? 'AjXdfmTTk1I9q9dfyePuDFHBrz1tCO3l'
: '0EXTgkNx0Ydje2PGXVbRhpKKoe5wtzcE'
// TODO: refactor into web components
let utilityServerRoot = isProd
? 'https://util.hashicorp.com'
: 'https://hashicorp-web-util-staging.herokuapp.com'
if (process.env.UTIL_SERVER) {
utilityServerRoot = process.env.UTIL_SERVER.replace(/\/$/, '')
}
// Consent manager configuration
export default {
version: 3,
container: '#consent-manager',
companyName: 'HashiCorp',
privacyPolicyLink: '/privacy',
segmentWriteKey: segmentWriteKey,
utilServerRoot: utilityServerRoot,
segmentServices: [
{
key: 'googleanalytics',
name: 'Google Analytics',
description:
'Google Analytics is a popular service for tracking web traffic. We use this data to determine what content our users find important so that we can dedicate more resources toward it.',
category: 'Analytics',
},
{
name: 'Hotjar',
description:
'Hotjar is a service that generates heatmaps of where users click on our sites. We use this information to ensure that our site is not confusing, and simple to use and navigate.',
category: 'Analytics',
},
{
name: 'LinkedIn Insight Tag',
description:
'This small script allows us to see how effective our linkedin campaigns are by showing which users have clicked through to our site.',
category: 'Analytics',
},
{
name: 'Marketo V2',
description:
'Marketo is a marketing automation tool that allows us to segment users into different categories based off of their behaviors. We use this information to provide tailored information to users in our email campaigns.',
},
],
categories: [
{
name: 'Functional',
description:
'Functional services provide a utility to the website, such as the ability to log in, or to get live support. Disabling any of these scripts will cause that utility to be missing from the site.',
},
{
name: 'Analytics',
description:
'Analytics services keep track of page traffic and user behavior while browsing the site. We use this data internally to improve the usability and performance of the site. Disabling any of these scripts makes it more difficult for us to understand how our site is being used, and slower to improve it.',
},
{
name: 'Email Marketing',
description:
'Email Marketing services track user behavior while browsing the site. We use this data internally in our marketing efforts to provide users contextually relevant information based off of their behaviors. Disabling any of these scripts makes it more difficult for us to provide you contextually relevant information.',
},
],
additionalServices: [
{
name: 'OptinMonster',
description:
"OptinMonster is a service that we use to show a prompt to sign up for our newsletter if it's perceived that you are interested in our content.",
category: 'Functional',
body: `var om598c8e3a6e43d,om598c8e3a6e43d_poll=function(){var r=0;return function(n,l){clearInterval(r),r=setInterval(n,l)}}();!function(e,t,n){if(e.getElementById(n)){om598c8e3a6e43d_poll(function(){if(window['om_loaded']){if(!om598c8e3a6e43d){om598c8e3a6e43d=new OptinMonsterApp();return om598c8e3a6e43d.init({"s":"35109.598c8e3a6e43d","staging":0,"dev":0,"beta":0});}}},25);return;}var d=false,o=e.createElement(t);o.id=n,o.src="https://a.optnmstr.com/app/js/api.min.js",o.async=true,o.onload=o.onreadystatechange=function(){if(!d){if(!this.readyState||this.readyState==="loaded"||this.readyState==="complete"){try{d=om_loaded=true;om598c8e3a6e43d=new OptinMonsterApp();om598c8e3a6e43d.init({"s":"35109.598c8e3a6e43d","staging":0,"dev":0,"beta":0});o.onload=o.onreadystatechange=null;}catch(t){}}}};(document.getElementsByTagName("head")[0]||document.documentElement).appendChild(o)}(document,"script","omapi-script");`,
},
],
}

View File

@ -7,10 +7,10 @@
command = "npm run static" command = "npm run static"
[context.production] [context.production]
environment = { HASHI_ENV = "production", NODE_ENV = "production"} environment = { HASHI_ENV = "production", NODE_ENV = "production" }
[context.deploy-preview] [context.deploy-preview]
environment = { HASHI_ENV = "staging" } environment = { HASHI_ENV = "staging", NODE_ENV = "production" }
[[headers]] [[headers]]
for = "/*" for = "/*"

View File

@ -7,7 +7,6 @@ module.exports = withHashicorp({
mdx: { resolveIncludes: path.join(__dirname, 'pages/partials') }, mdx: { resolveIncludes: path.join(__dirname, 'pages/partials') },
})({ })({
experimental: { experimental: {
css: true,
modern: true, modern: true,
rewrites: () => [ rewrites: () => [
{ {
@ -19,5 +18,8 @@ module.exports = withHashicorp({
exportTrailingSlash: true, exportTrailingSlash: true,
env: { env: {
HASHI_ENV: process.env.HASHI_ENV, HASHI_ENV: process.env.HASHI_ENV,
SEGMENT_WRITE_KEY: 'AjXdfmTTk1I9q9dfyePuDFHBrz1tCO3l',
BUGSNAG_CLIENT_KEY: 'de0b822b269aa57b620efd8927e03744',
BUGSNAG_SERVER_KEY: 'b6c57b27a37e531a5de94f065dd98bc0',
}, },
}) })

32
website/pages/404.jsx Normal file
View File

@ -0,0 +1,32 @@
import Link from 'next/link'
import { useEffect } from 'react'
export default function NotFound() {
useEffect(() => {
if (
typeof window !== 'undefined' &&
typeof window?.analytics?.track === 'function' &&
typeof window?.document?.referrer === 'string' &&
typeof window?.location?.href === 'string'
)
window.analytics.track(window.location.href, {
category: '404 Response',
label: window.document.referrer || 'No Referrer',
})
}, [])
return (
<div id="p-404">
<h1>Page Not Found</h1>
<p>
We&apos;re sorry but we can&apos;t find the page you&apos;re looking
for.
</p>
<p>
<Link href="/">
<a>Back to Home</a>
</Link>
</p>
</div>
)
}

View File

@ -1,87 +1,78 @@
import './style.css' import './style.css'
import App from 'next/app' import '@hashicorp/nextjs-scripts/lib/nprogress/style.css'
import NProgress from 'nprogress'
import Router from 'next/router' import ProductSubnav from 'components/subnav'
import ProductSubnav from '../components/subnav'
import MegaNav from '@hashicorp/react-mega-nav' import MegaNav from '@hashicorp/react-mega-nav'
import Footer from '../components/footer' import Footer from 'components/footer'
import { ConsentManager, open } from '@hashicorp/react-consent-manager'
import consentManagerConfig from '../lib/consent-manager-config'
import bugsnagClient from '../lib/bugsnag'
import Error from './_error' import Error from './_error'
import Head from 'next/head' import Head from 'next/head'
import HashiHead from '@hashicorp/react-head' import HashiHead from '@hashicorp/react-head'
import Router from 'next/router'
import NProgress from '@hashicorp/nextjs-scripts/lib/nprogress'
import createConsentManager from '@hashicorp/nextjs-scripts/lib/consent-manager'
import { ErrorBoundary } from '@hashicorp/nextjs-scripts/lib/bugsnag'
import useAnchorLinkAnalytics from '@hashicorp/nextjs-scripts/lib/anchor-link-analytics'
Router.events.on('routeChangeStart', NProgress.start) NProgress({ Router })
Router.events.on('routeChangeError', NProgress.done) const { ConsentManager, openConsentManager } = createConsentManager({
Router.events.on('routeChangeComplete', (url) => { preset: 'oss',
setTimeout(() => window.analytics.page(url), 0)
NProgress.done()
}) })
// Bugsnag export default function App({ Component, pageProps }) {
const ErrorBoundary = bugsnagClient.getPlugin('react') useAnchorLinkAnalytics()
class NextApp extends App { return (
static async getInitialProps({ Component, ctx }) { <ErrorBoundary FallbackComponent={Error}>
let pageProps = {} <HashiHead
is={Head}
if (Component.getInitialProps) { title="Packer by HashiCorp"
pageProps = await Component.getInitialProps(ctx) siteName="Packer by HashiCorp"
} else if (Component.isMDXComponent) { description="Packer is a free and open source tool for creating golden images for multiple
// fix for https://github.com/mdx-js/mdx/issues/382 platforms from a single source configuration."
const mdxLayoutComponent = Component({}).props.originalType image="https://www.packer.io/img/og-image.png"
if (mdxLayoutComponent.getInitialProps) { stylesheet={[
pageProps = await mdxLayoutComponent.getInitialProps(ctx) {
} href:
} 'https://fonts.googleapis.com/css?family=Open+Sans:300,400,600,700&display=swap',
},
return { pageProps } ]}
} icon={[{ href: '/favicon.ico' }]}
preload={[
render() { { href: '/fonts/klavika/medium.woff2', as: 'font' },
const { Component, pageProps } = this.props { href: '/fonts/gilmer/light.woff2', as: 'font' },
{ href: '/fonts/gilmer/regular.woff2', as: 'font' },
return ( { href: '/fonts/gilmer/medium.woff2', as: 'font' },
<ErrorBoundary FallbackComponent={Error}> { href: '/fonts/gilmer/bold.woff2', as: 'font' },
<HashiHead { href: '/fonts/metro-sans/book.woff2', as: 'font' },
is={Head} { href: '/fonts/metro-sans/regular.woff2', as: 'font' },
title="Packer by HashiCorp" { href: '/fonts/metro-sans/semi-bold.woff2', as: 'font' },
siteName="Packer by HashiCorp" { href: '/fonts/metro-sans/bold.woff2', as: 'font' },
description="Packer is a free and open source tool for creating golden images for multiple { href: '/fonts/dejavu/mono.woff2', as: 'font' },
platforms from a single source configuration." ]}
image="https://www.packer.io/img/og-image.png" />
stylesheet={[ <MegaNav product="Packer" />
{ href: '/css/nprogress.css' }, <ProductSubnav />
{ <div className="content">
href: <Component {...pageProps} />
'https://fonts.googleapis.com/css?family=Open+Sans:300,400,600,700&display=swap', </div>
}, <Footer openConsentManager={openConsentManager} />
]} <ConsentManager />
icon={[{ href: '/favicon.ico' }]} </ErrorBoundary>
preload={[ )
{ href: '/fonts/klavika/medium.woff2', as: 'font' },
{ href: '/fonts/gilmer/light.woff2', as: 'font' },
{ href: '/fonts/gilmer/regular.woff2', as: 'font' },
{ href: '/fonts/gilmer/medium.woff2', as: 'font' },
{ href: '/fonts/gilmer/bold.woff2', as: 'font' },
{ href: '/fonts/metro-sans/book.woff2', as: 'font' },
{ href: '/fonts/metro-sans/regular.woff2', as: 'font' },
{ href: '/fonts/metro-sans/semi-bold.woff2', as: 'font' },
{ href: '/fonts/metro-sans/bold.woff2', as: 'font' },
{ href: '/fonts/dejavu/mono.woff2', as: 'font' },
]}
/>
<MegaNav product="Packer" />
<ProductSubnav />
<div className="content">
<Component {...pageProps} />
</div>
<Footer openConsentManager={open} />
<ConsentManager {...consentManagerConfig} />
</ErrorBoundary>
)
}
} }
export default NextApp App.getInitialProps = async ({ Component, ctx }) => {
let pageProps = {}
if (Component.getInitialProps) {
pageProps = await Component.getInitialProps(ctx)
} else if (Component.isMDXComponent) {
// fix for https://github.com/mdx-js/mdx/issues/382
const mdxLayoutComponent = Component({}).props.originalType
if (mdxLayoutComponent.getInitialProps) {
pageProps = await mdxLayoutComponent.getInitialProps(ctx)
}
}
return { pageProps }
}

View File

@ -17,7 +17,7 @@ export default class MyDocument extends Document {
<script <script
noModule noModule
dangerouslySetInnerHTML={{ dangerouslySetInnerHTML={{
__html: `window.MSInputMethodContext && document.documentMode && document.write('<script src="/ie-custom-properties.js"><\\x2fscript>');` __html: `window.MSInputMethodContext && document.documentMode && document.write('<script src="/ie-custom-properties.js"><\\x2fscript>');`,
}} }}
/> />
</body> </body>

View File

@ -1,13 +1,14 @@
import React from 'react' import NotFound from './404'
import ErrorPage from 'next/error' import Bugsnag from '@hashicorp/nextjs-scripts/lib/bugsnag'
import bugsnagClient from '../lib/bugsnag'
export default class Page extends React.Component { function Error({ statusCode }) {
static async getInitialProps(ctx) { return <NotFound statusCode={statusCode} />
if (ctx.err) bugsnagClient.notify(ctx.err)
return ErrorPage.getInitialProps(ctx)
}
render() {
return <ErrorPage statusCode={this.props.statusCode || '¯\\_(ツ)_/¯'} />
}
} }
Error.getInitialProps = ({ res, err }) => {
if (err) Bugsnag.notify(err)
const statusCode = res ? res.statusCode : err ? err.statusCode : 404
return { statusCode }
}
export default Error

View File

@ -256,7 +256,7 @@ below.
autogenerated_password_https_boostrap.txt autogenerated_password_https_boostrap.txt
``` ps1 ```powershell
<powershell> <powershell>
# MAKE SURE IN YOUR PACKER CONFIG TO SET: # MAKE SURE IN YOUR PACKER CONFIG TO SET:
@ -308,15 +308,15 @@ cmd.exe /c net start winrm
You'll notice that this config does not define a user or password; instead, You'll notice that this config does not define a user or password; instead,
Packer will ask AWS to provide a random password that it generates Packer will ask AWS to provide a random password that it generates
automatically. The following config will work with the above template: automatically. The following config will work with the above template:
``` ```json
{ {
"builders": [ "builders": [
{ {
"type": "amazon-ebs", "type": "amazon-ebs",
"region": "us-east-1", "region": "us-east-1",
"instance_type": "t2.micro", "instance_type": "t2.micro",
"source_ami_filter": { "source_ami_filter": {
"filters": { "filters": {
"virtualization-type": "hvm", "virtualization-type": "hvm",
@ -326,18 +326,18 @@ automatically. The following config will work with the above template:
"most_recent": true, "most_recent": true,
"owners": "amazon" "owners": "amazon"
}, },
"ami_name": "default-packer", "ami_name": "default-packer",
"user_data_file": "winrm_bootstrap.txt", "user_data_file": "winrm_bootstrap.txt",
"communicator": "winrm", "communicator": "winrm",
"force_deregister": true, "force_deregister": true,
"winrm_insecure": true, "winrm_insecure": true,
"winrm_username": "Administrator", "winrm_username": "Administrator",
"winrm_use_ssl": true "winrm_use_ssl": true
}] }
]
} }
``` ```
## Windows 2016 Sysprep Commands - For Amazon Windows AMIs Only ## Windows 2016 Sysprep Commands - For Amazon Windows AMIs Only
For Amazon Windows 2016 AMIs it is necessary to run Sysprep commands which can For Amazon Windows 2016 AMIs it is necessary to run Sysprep commands which can

View File

@ -202,8 +202,8 @@ multiple lines for convenience of reading. The bundle volume command is
responsible for executing `ec2-bundle-vol` in order to store and image of the responsible for executing `ec2-bundle-vol` in order to store and image of the
root filesystem to use to create the AMI. root filesystem to use to create the AMI.
```text ```shell-session
sudo -i -n ec2-bundle-vol \ $ sudo -i -n ec2-bundle-vol \
-k {{.KeyPath}} \ -k {{.KeyPath}} \
-u {{.AccountId}} \ -u {{.AccountId}} \
-c {{.CertPath}} \ -c {{.CertPath}} \
@ -230,8 +230,8 @@ across multiple lines for convenience of reading. Access key and secret key are
omitted if using instance profile. The bundle upload command is responsible for omitted if using instance profile. The bundle upload command is responsible for
taking the bundled volume and uploading it to S3. taking the bundled volume and uploading it to S3.
```text ```shell-session
sudo -i -n ec2-upload-bundle \ $ sudo -i -n ec2-upload-bundle \
-b {{.BucketName}} \ -b {{.BucketName}} \
-m {{.ManifestPath}} \ -m {{.ManifestPath}} \
-a {{.AccessKey}} \ -a {{.AccessKey}} \

View File

@ -73,18 +73,20 @@ information.
@include 'builder/azure/chroot/Config-not-required.mdx' @include 'builder/azure/chroot/Config-not-required.mdx'
#### Output options: #### Output options:
At least one of these options needs to be specified: At least one of these options needs to be specified:
- `image_resource_id` (string) - The managed image to create using this build.
- `image_resource_id` (string) - The managed image to create using this build.
- `shared_image_destination` (object) - The shared image to create using this build.
- `shared_image_destination` (object) - The shared image to create using this build.
Where `shared_image_destination` is an object with the following properties: Where `shared_image_destination` is an object with the following properties:
@include 'builder/azure/chroot/_SharedImageGalleryDestination-required.mdx @include 'builder/azure/chroot/\_SharedImageGalleryDestination-required.mdx
@include 'builder/azure/chroot/_SharedImageGalleryDestination-not-required.mdx @include 'builder/azure/chroot/\_SharedImageGalleryDestination-not-required.mdx
And `target_regions` is an array of objects with the following properties: And `target_regions` is an array of objects with the following properties:
@include 'builder/azure/chroot/_TargetRegion-required.mdx @include 'builder/azure/chroot/\_TargetRegion-required.mdx
@include 'builder/azure/chroot/_TargetRegion-not-required.mdx @include 'builder/azure/chroot/\_TargetRegion-not-required.mdx
## Chroot Mounts ## Chroot Mounts
@ -148,8 +150,8 @@ This builder requires privileged actions, such as mounting disks, running
`chroot` and other admin commands. Usually it needs to be run with root `chroot` and other admin commands. Usually it needs to be run with root
permissions, for example: permissions, for example:
```shell ```shell-session
sudo -E packer build example.json $ sudo -E packer build example.json
``` ```
### Using a VM with a Managed Identity ### Using a VM with a Managed Identity

View File

@ -190,7 +190,7 @@ handles pushing the image to a container repository.
If you want to do this manually, however, perhaps from a script, you can import If you want to do this manually, however, perhaps from a script, you can import
the image using the process below: the image using the process below:
```shell ```shell-session
$ docker import - registry.mydomain.com/mycontainer:latest < artifact.tar $ docker import - registry.mydomain.com/mycontainer:latest < artifact.tar
``` ```

View File

@ -44,7 +44,7 @@ scopes when launching the instance.
For `gcloud`, do this via the `--scopes` parameter: For `gcloud`, do this via the `--scopes` parameter:
```shell ```shell-session
$ gcloud compute instances create INSTANCE-NAME \ $ gcloud compute instances create INSTANCE-NAME \
--project YOUR_GCP_PROJECT \ --project YOUR_GCP_PROJECT \
--image-family ubuntu-1804-lts \ --image-family ubuntu-1804-lts \

View File

@ -56,8 +56,8 @@ machine, HyperOne builder can use your credentials saved in a config file.
All you have to do is login within the tool: All you have to do is login within the tool:
```bash ```shell-session
h1 login --username your.user@example.com $ h1 login --username your.user@example.com
``` ```
You don't have to set `token` or `project` fields at all using this method. You don't have to set `token` or `project` fields at all using this method.
@ -66,8 +66,8 @@ You don't have to set `token` or `project` fields at all using this method.
Using `h1`, you can create a new token associated with chosen project. Using `h1`, you can create a new token associated with chosen project.
```bash ```shell-session
h1 project token add --name packer-builder --project PROJECT_ID $ h1 project token add --name packer-builder --project PROJECT_ID
``` ```
Set the `token` field to the generated token or save it in the `HYPERONE_TOKEN` Set the `token` field to the generated token or save it in the `HYPERONE_TOKEN`
@ -279,4 +279,4 @@ build {
] ]
} }
} }
``` ```

View File

@ -215,7 +215,7 @@ substituted with the letter `a` and OCIDS have been shortened for brevity.
} }
``` ```
```text ```shell-session
[opc@packerhost ~]$ packer build packer.json [opc@packerhost ~]$ packer build packer.json
oracle-oci: output will be in this color. oracle-oci: output will be in this color.

View File

@ -22,7 +22,7 @@ image).
When exporting from VirtualBox make sure to choose OVF Version 2, since Version When exporting from VirtualBox make sure to choose OVF Version 2, since Version
1 is not compatible and will generate errors like this: 1 is not compatible and will generate errors like this:
```shell ```shell-session
==> virtualbox-ovf: Progress state: VBOX_E_FILE_ERROR ==> virtualbox-ovf: Progress state: VBOX_E_FILE_ERROR
==> virtualbox-ovf: VBoxManage: error: Appliance read failed ==> virtualbox-ovf: VBoxManage: error: Appliance read failed
==> virtualbox-ovf: VBoxManage: error: Error reading "source.ova": element "Section" has no "type" attribute, line 21 ==> virtualbox-ovf: VBoxManage: error: Error reading "source.ova": element "Section" has no "type" attribute, line 21

View File

@ -20,7 +20,7 @@ Type in the interpolation to test and hit \<enter\> to see the result.
To exit the console, type "exit" and hit \<enter\>, or use Control-C. To exit the console, type "exit" and hit \<enter\>, or use Control-C.
```shell ```shell-session
$ packer console my_template.json $ packer console my_template.json
``` ```
@ -49,7 +49,7 @@ help output, which can be seen via `packer console -h`.
Let's say you launch a console using a Packer template `example_template.json`: Let's say you launch a console using a Packer template `example_template.json`:
```shell ```shell-session
$ packer console example_template.json $ packer console example_template.json
``` ```
@ -67,29 +67,29 @@ your example_template's variable section:
and you enter `` {{user `myvar`}} `` in the Packer console, you'll see the value of and you enter `` {{user `myvar`}} `` in the Packer console, you'll see the value of
myvar: myvar:
```shell ```shell-session
> {{user `myvar`}} > {{user `myvar`}}
> asdfasdf > asdfasdf
``` ```
From there you can test more complicated interpolations: From there you can test more complicated interpolations:
```shell ```shell-session
> {{user `myvar`}}-{{timestamp}} > {{user `myvar`}}-{{timestamp}}
> asdfasdf-1559854396 > asdfasdf-1559854396
``` ```
And when you're done using the console, just type "exit" or CTRL-C And when you're done using the console, just type "exit" or CTRL-C
```shell ```shell-session
> exit > exit
$ $
``` ```
If you'd like to provide a variable or variable files, you'd do this: If you'd like to provide a variable or variable files, you'd do this:
```shell ```shell-session
packer console -var "myvar=fdsafdsa" -var-file myvars.json example_template.json $ packer console -var "myvar=fdsafdsa" -var-file myvars.json example_template.json
``` ```
If you don't have specific variables or var files you want to test, and just If you don't have specific variables or var files you want to test, and just
@ -100,7 +100,7 @@ If you'd like to just see a specific single interpolation without launching
the REPL, you can do so by echoing and piping the string into the console the REPL, you can do so by echoing and piping the string into the console
command: command:
```shell ```shell-session
$ echo {{timestamp}} | packer console $ echo {{timestamp}} | packer console
1559855090 1559855090
``` ```

View File

@ -20,7 +20,7 @@ The fix command will output the changed template to standard out, so you should
redirect standard using standard OS-specific techniques if you want to save it redirect standard using standard OS-specific techniques if you want to save it
to a file. For example, on Linux systems, you may want to do this: to a file. For example, on Linux systems, you may want to do this:
```shell ```shell-session
$ packer fix old.json > new.json $ packer fix old.json > new.json
``` ```

View File

@ -46,7 +46,7 @@ The machine-readable output format can be enabled by passing the
output to become machine-readable on stdout. Logging, if enabled, continues to output to become machine-readable on stdout. Logging, if enabled, continues to
appear on stderr. An example of the output is shown below: appear on stderr. An example of the output is shown below:
```text ```shell-session
$ packer -machine-readable version $ packer -machine-readable version
1498365963,,version,1.0.2 1498365963,,version,1.0.2
1498365963,,version-prelease, 1498365963,,version-prelease,
@ -127,7 +127,7 @@ You'll see these data types when you run `packer build`:
For example: For example:
```shell ```text
1539967803,,ui,say,\n==> Builds finished. The artifacts of successful builds are: 1539967803,,ui,say,\n==> Builds finished. The artifacts of successful builds are:
1539967803,amazon-ebs,artifact-count,2 1539967803,amazon-ebs,artifact-count,2
1539967803,amazon-ebs,artifact,0,builder-id,mitchellh.amazonebs 1539967803,amazon-ebs,artifact,0,builder-id,mitchellh.amazonebs
@ -162,7 +162,7 @@ can invoke a new shell and use the feature.
For example, assume a tab is typed at the end of each prompt line: For example, assume a tab is typed at the end of each prompt line:
```shell ```shell-session
$ packer p $ packer p
plugin build plugin build
$ packer build - $ packer build -

View File

@ -35,7 +35,7 @@ of your template by necessity.
Given a basic template, here is an example of what the output might look like: Given a basic template, here is an example of what the output might look like:
```text ```shell-session
$ packer inspect template.json $ packer inspect template.json
Variables and their defaults: Variables and their defaults:

View File

@ -19,7 +19,7 @@ outputted.
Example usage: Example usage:
```text ```shell-session
$ packer validate my-template.json $ packer validate my-template.json
Template validation failed. Errors are shown below. Template validation failed. Errors are shown below.

View File

@ -18,7 +18,7 @@ chunklist(list, chunk_size)
## Examples ## Examples
```text ```shell-session
> chunklist(["a", "b", "c", "d", "e"], 2) > chunklist(["a", "b", "c", "d", "e"], 2)
[ [
["a", "b"], ["a", "b"],

View File

@ -14,7 +14,7 @@ that isn't null or an empty string.
## Examples ## Examples
```shell ```shell-session
> coalesce("a", "b") > coalesce("a", "b")
a a
> coalesce("", "b") > coalesce("", "b")
@ -26,7 +26,7 @@ b
To perform the `coalesce` operation with a list of strings, use the `...` To perform the `coalesce` operation with a list of strings, use the `...`
symbol to expand the list as arguments: symbol to expand the list as arguments:
```shell ```shell-session
> coalesce(["", "b"]...) > coalesce(["", "b"]...)
b b
``` ```

View File

@ -14,7 +14,7 @@ that isn't empty.
## Examples ## Examples
```shell ```shell-session
> coalescelist(["a", "b"], ["c", "d"]) > coalescelist(["a", "b"], ["c", "d"])
[ [
"a", "a",
@ -30,7 +30,7 @@ that isn't empty.
To perform the `coalescelist` operation with a list of lists, use the `...` To perform the `coalescelist` operation with a list of lists, use the `...`
symbol to expand the outer list as arguments: symbol to expand the outer list as arguments:
```shell ```shell-session
> coalescelist([[], ["c", "d"]]...) > coalescelist([[], ["c", "d"]]...)
[ [
"c", "c",

View File

@ -12,7 +12,7 @@ elements removed.
## Examples ## Examples
```shell ```shell-session
> compact(["a", "", "b", "c"]) > compact(["a", "", "b", "c"])
[ [
"a", "a",

View File

@ -11,7 +11,7 @@ description: The concat function combines two or more lists into a single list.
## Examples ## Examples
```shell ```shell-session
> concat(["a", ""], ["b", "c"]) > concat(["a", ""], ["b", "c"])
[ [
"a", "a",

View File

@ -16,7 +16,7 @@ contains(list, value)
## Examples ## Examples
```shell ```shell-session
> contains(["a", "b", "c"], "a") > contains(["a", "b", "c"], "a")
true true
> contains(["a", "b", "c"], "d") > contains(["a", "b", "c"], "d")

View File

@ -15,7 +15,7 @@ these elements is preserved.
## Examples ## Examples
```shell ```shell-session
> distinct(["a", "b", "a", "c", "d", "b"]) > distinct(["a", "b", "a", "c", "d", "b"])
[ [
"a", "a",

View File

@ -21,7 +21,7 @@ only for the special additional "wrap-around" behavior described below.
## Examples ## Examples
```shell ```shell-session
> element(["a", "b", "c"], 1) > element(["a", "b", "c"], 1)
b b
``` ```
@ -29,7 +29,7 @@ b
If the given index is greater than the length of the list then the index is If the given index is greater than the length of the list then the index is
"wrapped around" by taking the index modulo the length of the list: "wrapped around" by taking the index modulo the length of the list:
```shell ```shell-session
> element(["a", "b", "c"], 3) > element(["a", "b", "c"], 3)
a a
``` ```

View File

@ -12,7 +12,7 @@ flattened sequence of the list contents.
## Examples ## Examples
```shell ```shell-session
> flatten([["a", "b"], [], ["c"]]) > flatten([["a", "b"], [], ["c"]])
["a", "b", "c"] ["a", "b", "c"]
``` ```
@ -20,7 +20,7 @@ flattened sequence of the list contents.
If any of the nested lists also contain directly-nested lists, these too are If any of the nested lists also contain directly-nested lists, these too are
flattened recursively: flattened recursively:
```shell ```shell-session
> flatten([[["a", "b"], []], ["c"]]) > flatten([[["a", "b"], []], ["c"]])
["a", "b", "c"] ["a", "b", "c"]
``` ```

View File

@ -18,7 +18,7 @@ value is not present in the list.
## Examples ## Examples
```shell ```shell-session
> index(["a", "b", "c"], "b") > index(["a", "b", "c"], "b")
1 1
``` ```

View File

@ -14,7 +14,7 @@ be identical as long as the keys in the map don't change.
## Examples ## Examples
```shell ```shell-session
> keys({a=1, c=2, d=3}) > keys({a=1, c=2, d=3})
[ [
"a", "a",

View File

@ -14,7 +14,7 @@ If given a string, the result is the number of characters in the string.
## Examples ## Examples
```shell ```shell-session
> length([]) > length([])
0 0
> length(["a", "b"]) > length(["a", "b"])
@ -28,7 +28,7 @@ If given a string, the result is the number of characters in the string.
When given a string, the result is the number of characters, rather than the When given a string, the result is the number of characters, rather than the
number of bytes or Unicode sequences that form them: number of bytes or Unicode sequences that form them:
```shell ```shell-session
> length("👾🕹️") > length("👾🕹️")
2 2
``` ```

View File

@ -20,7 +20,7 @@ equivalent to the native index syntax, `map[key]`.
## Examples ## Examples
```shell ```shell-session
> lookup({a="ay", b="bee"}, "a", "what?") > lookup({a="ay", b="bee"}, "a", "what?")
ay ay
> lookup({a="ay", b="bee"}, "c", "what?") > lookup({a="ay", b="bee"}, "c", "what?")

View File

@ -17,7 +17,7 @@ in the argument sequence takes precedence.
## Examples ## Examples
```shell ```shell-session
> merge({"a"="b", "c"="d"}, {"e"="f", "c"="z"}) > merge({"a"="b", "c"="d"}, {"e"="f", "c"="z"})
{ {
"a" = "b" "a" = "b"

View File

@ -51,7 +51,7 @@ functions or `for` expressions.
## Examples ## Examples
```shell ```shell-session
> range(3) > range(3)
[ [
0, 0,

View File

@ -12,7 +12,7 @@ with all of the same elements as the given sequence but in reverse order.
## Examples ## Examples
```shell ```shell-session
> reverse([1, 2, 3]) > reverse([1, 2, 3])
[ [
3, 3,

View File

@ -20,7 +20,7 @@ setintersection(sets...)
## Examples ## Examples
```shell ```shell-session
> setintersection(["a", "b"], ["b", "c"], ["b", "d"]) > setintersection(["a", "b"], ["b", "c"], ["b", "d"])
[ [
"b", "b",

View File

@ -21,7 +21,7 @@ This function is particularly useful for finding the exhaustive set of all
combinations of members of multiple sets, such as per-application-per-environment combinations of members of multiple sets, such as per-application-per-environment
resources. resources.
```shell ```shell-session
> setproduct(["development", "staging", "production"], ["app1", "app2"]) > setproduct(["development", "staging", "production"], ["app1", "app2"])
[ [
[ [
@ -68,7 +68,7 @@ reusable folder situations.
If any of the arguments is empty then the result is always empty itself, If any of the arguments is empty then the result is always empty itself,
similar to how multiplying any number by zero gives zero: similar to how multiplying any number by zero gives zero:
```shell ```shell-session
> setproduct(["development", "staging", "production"], []) > setproduct(["development", "staging", "production"], [])
[] []
``` ```
@ -76,7 +76,7 @@ similar to how multiplying any number by zero gives zero:
Similarly, if all of the arguments have only one element then the result has Similarly, if all of the arguments have only one element then the result has
only one element, which is the first element of each argument: only one element, which is the first element of each argument:
```shell ```shell-session
> setproduct(["a"], ["b"]) > setproduct(["a"], ["b"])
[ [
[ [
@ -92,7 +92,7 @@ error if such a conversion is impossible. For example, mixing both strings and
numbers results in the numbers being converted to strings so that the result numbers results in the numbers being converted to strings so that the result
elements all have a consistent type: elements all have a consistent type:
```shell ```shell-session
> setproduct(["staging", "production"], ["a", 2]) > setproduct(["staging", "production"], ["a", 2])
[ [
[ [

View File

@ -20,7 +20,7 @@ setunion(sets...)
## Examples ## Examples
```shell ```shell-session
> setunion(["a", "b"], ["b", "c"], ["d"]) > setunion(["a", "b"], ["b", "c"], ["d"])
[ [
"d", "d",

View File

@ -19,7 +19,7 @@ list.
## Examples ## Examples
```shell ```shell-session
> slice(["a", "b", "c", "d"], 1, 3) > slice(["a", "b", "c", "d"], 1, 3)
[ [
"b", "b",

View File

@ -17,7 +17,7 @@ after lower ones in the result.
## Examples ## Examples
```shell ```shell-session
> sort(["e", "d", "a", "x"]) > sort(["e", "d", "a", "x"])
[ [
"a", "a",

View File

@ -16,7 +16,7 @@ returned from [`keys`](/docs/from-1.5/functions/collection/keys).
## Examples ## Examples
```shell ```shell-session
> values({a=3, c=2, d=1}) > values({a=3, c=2, d=1})
[ [
3, 3,

View File

@ -26,7 +26,7 @@ is used in the resulting map.
## Examples ## Examples
```shell ```shell-session
> zipmap(["a", "b"], [1, 2]) > zipmap(["a", "b"], [1, 2])
{ {
"a" = 1, "a" = 1,

View File

@ -30,7 +30,7 @@ prefer to use [`try`](/docs/from-1.5/functions/conversion/try).
## Examples ## Examples
```shell ```shell-session
> local.foo > local.foo
{ {
"bar" = "baz" "bar" = "baz"
@ -45,7 +45,7 @@ The `can` function will _not_ catch errors relating to constructs that are
provably invalid even before dynamic expression evaluation, such as a malformed provably invalid even before dynamic expression evaluation, such as a malformed
reference or a reference to a top-level object that has not been declared: reference or a reference to a top-level object that has not been declared:
```shell ```shell-session
> can(local.nonexist) > can(local.nonexist)
Error: Reference to undeclared local value Error: Reference to undeclared local value

View File

@ -26,7 +26,7 @@ All other values will produce an error.
## Examples ## Examples
```shell ```shell-session
> convert(3, string) > convert(3, string)
"3" "3"
> convert("3", number) > convert("3", number)

View File

@ -84,7 +84,7 @@ to understand and maintain.
## Examples ## Examples
```shell ```shell-session
> local.foo > local.foo
{ {
"bar" = "baz" "bar" = "baz"
@ -99,7 +99,7 @@ The `try` function will _not_ catch errors relating to constructs that are
provably invalid even before dynamic expression evaluation, such as a malformed provably invalid even before dynamic expression evaluation, such as a malformed
reference or a reference to a top-level object that has not been declared: reference or a reference to a top-level object that has not been declared:
```shell ```shell-session
> try(local.nonexist, "fallback") > try(local.nonexist, "fallback")
Error: Reference to undeclared local value Error: Reference to undeclared local value

View File

@ -32,7 +32,7 @@ versions of Packer.
## Examples ## Examples
```text ```shell-session
> bcrypt("hello world") > bcrypt("hello world")
$2a$10$D5grTTzcsqyvAeIAnY/mYOIqliCoG7eAMX0/oFcuD.iErkksEbcAa $2a$10$D5grTTzcsqyvAeIAnY/mYOIqliCoG7eAMX0/oFcuD.iErkksEbcAa
``` ```

View File

@ -22,7 +22,7 @@ considerations applying to the MD5 algorithm.
## Examples ## Examples
```text ```shell-session
> md5("hello world") > md5("hello world")
5eb63bbbe01eeed093cb22bb8f5acdc3 5eb63bbbe01eeed093cb22bb8f5acdc3
``` ```

View File

@ -27,7 +27,7 @@ negotiated out-of-band.
## Examples ## Examples
```shell ```shell-session
> rsadecrypt(base64(file("${path.folder}/ciphertext")), file("privatekey.pem")) > rsadecrypt(base64(file("${path.folder}/ciphertext")), file("privatekey.pem"))
Hello, world! Hello, world!
``` ```

View File

@ -22,7 +22,7 @@ relevant literature to understand the security implications.
## Examples ## Examples
```shell ```shell-session
> sha1("hello world") > sha1("hello world")
2aae6c35c94fcfb415dbe95f408b9ce91ee846ed 2aae6c35c94fcfb415dbe95f408b9ce91ee846ed
``` ```

View File

@ -18,7 +18,7 @@ then encoded to lowercase hexadecimal digits before returning.
## Examples ## Examples
```shell ```shell-session
> sha256("hello world") > sha256("hello world")
b94d27b9934d3e08a52e52d7da7dabfac484efe37a5380ee9088f7ace2efcde9 b94d27b9934d3e08a52e52d7da7dabfac484efe37a5380ee9088f7ace2efcde9
``` ```

View File

@ -18,7 +18,7 @@ then encoded to lowercase hexadecimal digits before returning.
## Examples ## Examples
```shell ```shell-session
> sha512("hello world") > sha512("hello world")
309ecc489c12d6eb4cc40f50c902f2b4d0ed77ee511a7c7a9bcd3ca86d4cd86f989dd35bc5ff499670da34255b45b0cfd830e81f605dcf7dc5542e93ae9cd76f 309ecc489c12d6eb4cc40f50c902f2b4d0ed77ee511a7c7a9bcd3ca86d4cd86f989dd35bc5ff499670da34255b45b0cfd830e81f605dcf7dc5542e93ae9cd76f
``` ```

View File

@ -20,7 +20,7 @@ this syntax.
## Examples ## Examples
```shell ```shell-session
> formatdate("DD MMM YYYY hh:mm ZZZ", "2018-01-02T23:12:01Z") > formatdate("DD MMM YYYY hh:mm ZZZ", "2018-01-02T23:12:01Z")
02 Jan 2018 23:12 UTC 02 Jan 2018 23:12 UTC
> formatdate("EEEE, DD-MMM-YY hh:mm:ss ZZZ", "2018-01-02T23:12:01Z") > formatdate("EEEE, DD-MMM-YY hh:mm:ss ZZZ", "2018-01-02T23:12:01Z")
@ -75,7 +75,7 @@ Any non-letter characters, such as punctuation, are reproduced verbatim in the
output. To include literal letters in the format string, enclose them in single output. To include literal letters in the format string, enclose them in single
quotes `'`. To include a literal quote, escape it by doubling the quotes. quotes `'`. To include a literal quote, escape it by doubling the quotes.
```text ```shell-session
> formatdate("h'h'mm", "2018-01-02T23:12:01-08:00") > formatdate("h'h'mm", "2018-01-02T23:12:01-08:00")
23h12 23h12
> formatdate("H 'o''clock'", "2018-01-02T23:12:01-08:00") > formatdate("H 'o''clock'", "2018-01-02T23:12:01-08:00")

View File

@ -36,7 +36,7 @@ to format a date.
## Examples ## Examples
```shell ```shell-session
> timeadd("2017-11-22T00:00:00Z", "10m") > timeadd("2017-11-22T00:00:00Z", "10m")
2017-11-22T00:10:00Z 2017-11-22T00:10:00Z
``` ```

View File

@ -28,7 +28,7 @@ to format a date.
## Examples ## Examples
```text ```shell-session
> timestamp() > timestamp()
2018-05-13T07:44:12Z 2018-05-13T07:44:12Z
``` ```

View File

@ -27,7 +27,7 @@ or manipulate Base64 data directly.
## Examples ## Examples
```text ```shell-session
> base64decode("SGVsbG8gV29ybGQ=") > base64decode("SGVsbG8gV29ybGQ=")
Hello World Hello World
``` ```

View File

@ -28,7 +28,7 @@ data to be easily provided to resource types that expect Base64 bytes.
## Examples ## Examples
```text ```shell-session
> base64encode("Hello World") > base64encode("Hello World")
SGVsbG8gV29ybGQ= SGVsbG8gV29ybGQ=
``` ```

View File

@ -22,7 +22,7 @@ number of fields, or this function will produce an error.
## Examples ## Examples
```shell ```shell-session
> csvdecode("a,b,c\n1,2,3\n4,5,6") > csvdecode("a,b,c\n1,2,3\n4,5,6")
[ [
{ {

View File

@ -33,7 +33,7 @@ and can just use the result in an intuitive way.
## Examples ## Examples
```text ```shell-session
> jsondecode("{\"hello\": \"world\"}") > jsondecode("{\"hello\": \"world\"}")
{ {
"hello" = "world" "hello" = "world"

View File

@ -34,7 +34,7 @@ rarely a problem in practice.
## Examples ## Examples
```text ```shell-session
> jsonencode({"hello"="world"}) > jsonencode({"hello"="world"})
{"hello":"world"} {"hello":"world"}
``` ```

View File

@ -23,7 +23,7 @@ UTF-8 and then percent encoding is applied separately to each UTF-8 byte.
## Examples ## Examples
```text ```shell-session
> urlencode("Hello World") > urlencode("Hello World")
Hello%20World Hello%20World
> urlencode("☃") > urlencode("☃")

View File

@ -56,7 +56,7 @@ supports only a subset of YAML 1.2, with restrictions including the following:
## Examples ## Examples
```shell ```shell-session
> yamldecode("{\"hello\": \"world\"}") > yamldecode("{\"hello\": \"world\"}")
{ {
"hello" = "world" "hello" = "world"

View File

@ -53,7 +53,7 @@ mean that this is rarely a problem in practice.
## Examples ## Examples
```shell ```shell-session
> yamlencode({"a":"b", "c":"d"}) > yamlencode({"a":"b", "c":"d"})
"a": "b" "a": "b"
"c": "d" "c": "d"

View File

@ -19,7 +19,7 @@ only the contents are then stored) or in `connection` and `provisioner` blocks.
## Examples ## Examples
```shell ```shell-session
> abspath(path.root) > abspath(path.root)
/home/user/some/packer/root /home/user/some/packer/root
``` ```

View File

@ -31,7 +31,7 @@ only the contents are then stored) or in `connection` and `provisioner` blocks.
## Examples ## Examples
```text ```shell-session
> basename("foo/bar/baz.txt") > basename("foo/bar/baz.txt")
baz.txt baz.txt
``` ```

View File

@ -30,7 +30,7 @@ only the contents are then stored) or in `connection` and `provisioner` blocks.
## Examples ## Examples
```text ```shell-session
> dirname("foo/bar/baz.txt") > dirname("foo/bar/baz.txt")
foo/bar foo/bar
``` ```

View File

@ -32,7 +32,7 @@ to read files while respecting resource dependencies.
## Examples ## Examples
```text ```shell-session
> file("${path.folder}/hello.txt") > file("${path.folder}/hello.txt")
Hello World Hello World
``` ```

View File

@ -22,7 +22,7 @@ or other special mode, it will return an error.
## Examples ## Examples
```text ```shell-session
> fileexists("${path.folder}/hello.txt") > fileexists("${path.folder}/hello.txt")
true true
``` ```

View File

@ -36,7 +36,7 @@ before Packer takes any actions.
## Examples ## Examples
```text ```shell-session
> fileset(path.folder, "files/*.txt") > fileset(path.folder, "files/*.txt")
[ [
"files/hello.txt", "files/hello.txt",

View File

@ -48,7 +48,7 @@ releases of Packer.
## Examples ## Examples
```shell ```shell-session
> pathexpand("~/.ssh/id_rsa") > pathexpand("~/.ssh/id_rsa")
/home/steve/.ssh/id_rsa /home/steve/.ssh/id_rsa
> pathexpand("/etc/resolv.conf") > pathexpand("/etc/resolv.conf")

View File

@ -36,7 +36,7 @@ the same addressing scheme as the given prefix.
## Examples ## Examples
```text ```shell-session
> cidrhost("10.12.127.0/20", 16) > cidrhost("10.12.127.0/20", 16)
10.12.112.16 10.12.112.16
> cidrhost("10.12.127.0/20", 268) > cidrhost("10.12.127.0/20", 268)

View File

@ -27,7 +27,7 @@ produces an error if given an IPv6 address.
## Examples ## Examples
```text ```shell-session
> cidrnetmask("172.16.0.0/12") > cidrnetmask("172.16.0.0/12")
255.240.0.0 255.240.0.0
``` ```

View File

@ -36,7 +36,7 @@ with zero.
## Examples ## Examples
```text ```shell-session
> cidrsubnet("172.16.0.0/12", 4, 2) > cidrsubnet("172.16.0.0/12", 4, 2)
172.18.0.0/16 172.18.0.0/16
> cidrsubnet("10.1.2.0/24", 4, 15) > cidrsubnet("10.1.2.0/24", 4, 15)
@ -73,7 +73,7 @@ The CLI tool [`ipcalc`](https://gitlab.com/ipcalc/ipcalc) is useful for
visualizing CIDR prefixes as binary numbers. We can confirm the conversion visualizing CIDR prefixes as binary numbers. We can confirm the conversion
above by providing the same prefix string to `ipcalc`: above by providing the same prefix string to `ipcalc`:
```shell ```shell-session
$ ipcalc 10.1.2.0/24 $ ipcalc 10.1.2.0/24
Address: 10.1.2.0 00001010.00000001.00000010. 00000000 Address: 10.1.2.0 00001010.00000001.00000010. 00000000
Netmask: 255.255.255.0 = 24 11111111.11111111.11111111. 00000000 Netmask: 255.255.255.0 = 24 11111111.11111111.11111111. 00000000
@ -129,7 +129,7 @@ gives 240, which can then be combined with our new prefix length of 28 to
produce the result `10.1.2.240/28`. Again we can pass this prefix string to produce the result `10.1.2.240/28`. Again we can pass this prefix string to
`ipcalc` to visualize it: `ipcalc` to visualize it:
```shell ```shell-session
$ ipcalc 10.1.2.240/28 $ ipcalc 10.1.2.240/28
Address: 10.1.2.240 00001010.00000001.00000010.1111 0000 Address: 10.1.2.240 00001010.00000001.00000010.1111 0000
Netmask: 255.255.255.240 = 28 11111111.11111111.11111111.1111 0000 Netmask: 255.255.255.240 = 28 11111111.11111111.11111111.1111 0000
@ -148,7 +148,7 @@ the network's own address and the broadcast address. You can thus use
[`cidrhost`](/docs/from-1.5/functions/ipnet/cidrhost) function to calculate those host addresses by [`cidrhost`](/docs/from-1.5/functions/ipnet/cidrhost) function to calculate those host addresses by
providing it a value between 1 and 14: providing it a value between 1 and 14:
```shell ```shell-session
> cidrhost("10.1.2.240/28", 1) > cidrhost("10.1.2.240/28", 1)
10.1.2.241 10.1.2.241
> cidrhost("10.1.2.240/28", 14) > cidrhost("10.1.2.240/28", 14)

View File

@ -40,7 +40,7 @@ the same addressing scheme as the given prefix.
## Examples ## Examples
```text ```shell-session
> cidrsubnets("10.1.0.0/16", 4, 4, 8, 4) > cidrsubnets("10.1.0.0/16", 4, 4, 8, 4)
[ [
"10.1.0.0/20", "10.1.0.0/20",
@ -62,7 +62,7 @@ You can use nested `cidrsubnets` calls with
[`for` expressions](/docs/from-1.5/expressions#for-expressions) [`for` expressions](/docs/from-1.5/expressions#for-expressions)
to concisely allocate groups of network address blocks: to concisely allocate groups of network address blocks:
```text ```shell-session
> [for cidr_block in cidrsubnets("10.0.0.0/8", 8, 8, 8, 8) : cidrsubnets(cidr_block, 4, 4)] > [for cidr_block in cidrsubnets("10.0.0.0/8", 8, 8, 8, 8) : cidrsubnets(cidr_block, 4, 4)]
[ [
[ [

View File

@ -13,7 +13,7 @@ then it is multiplied by -1 to make it positive before returning it.
## Examples ## Examples
```text ```shell-session
> abs(23) > abs(23)
23 23
> abs(0) > abs(0)

View File

@ -14,7 +14,7 @@ given value, which may be a fraction.
## Examples ## Examples
```text ```shell-session
> ceil(5) > ceil(5)
5 5
> ceil(5.1) > ceil(5.1)

View File

@ -14,7 +14,7 @@ given value, which may be a fraction.
## Examples ## Examples
```text ```shell-session
> floor(5) > floor(5)
5 5
> floor(4.9) > floor(4.9)

View File

@ -15,7 +15,7 @@ log(number, base)
## Examples ## Examples
```text ```shell-session
> log(50, 10) > log(50, 10)
1.6989700043360185 1.6989700043360185
> log(16, 2) > log(16, 2)
@ -25,7 +25,7 @@ log(number, base)
`log` and `ceil` can be used together to find the minimum number of binary `log` and `ceil` can be used together to find the minimum number of binary
digits required to represent a given number of distinct values: digits required to represent a given number of distinct values:
```text ```shell-session
> ceil(log(15, 2)) > ceil(log(15, 2))
4 4
> ceil(log(16, 2)) > ceil(log(16, 2))

View File

@ -11,7 +11,7 @@ description: The max function takes one or more numbers and returns the greatest
## Examples ## Examples
```text ```shell-session
> max(12, 54, 3) > max(12, 54, 3)
54 54
``` ```
@ -19,7 +19,7 @@ description: The max function takes one or more numbers and returns the greatest
If the numbers are in a list or set value, use `...` to expand the collection If the numbers are in a list or set value, use `...` to expand the collection
to individual arguments: to individual arguments:
```text ```shell-session
> max([12, 54, 3]...) > max([12, 54, 3]...)
54 54
``` ```

View File

@ -11,7 +11,7 @@ description: The min function takes one or more numbers and returns the smallest
## Examples ## Examples
```text ```shell-session
> min(12, 54, 3) > min(12, 54, 3)
3 3
``` ```
@ -19,7 +19,7 @@ description: The min function takes one or more numbers and returns the smallest
If the numbers are in a list or set value, use `...` to expand the collection If the numbers are in a list or set value, use `...` to expand the collection
to individual arguments: to individual arguments:
```text ```shell-session
> min([12, 54, 3]...) > min([12, 54, 3]...)
3 3
``` ```

View File

@ -23,7 +23,7 @@ are too large for the given base then `parseint` will produce an error.
## Examples ## Examples
```shell ```shell-session
> parseint("100", 10) > parseint("100", 10)
100 100

View File

@ -11,7 +11,7 @@ description: The pow function raises a number to a power.
## Examples ## Examples
```text ```shell-session
> pow(3, 2) > pow(3, 2)
9 9
> pow(4, 0) > pow(4, 0)

View File

@ -12,7 +12,7 @@ description: The signum function determines the sign of a number.
## Examples ## Examples
```text ```shell-session
> signum(-13) > signum(-13)
-1 -1
> signum(0) > signum(0)

View File

@ -14,7 +14,7 @@ a newline character at the end.
## Examples ## Examples
```text ```shell-session
> chomp("hello\n") > chomp("hello\n")
hello hello
> chomp("hello\r\n") > chomp("hello\r\n")

View File

@ -19,7 +19,7 @@ format(spec, values...)
## Examples ## Examples
```text ```shell-session
> format("Hello, %s!", "Ander") > format("Hello, %s!", "Ander")
Hello, Ander! Hello, Ander!
> format("There are %d lights", 4) > format("There are %d lights", 4)
@ -29,7 +29,7 @@ There are 4 lights
Simple format verbs like `%s` and `%d` behave similarly to template Simple format verbs like `%s` and `%d` behave similarly to template
interpolation syntax, which is often more readable: interpolation syntax, which is often more readable:
```text ```shell-session
> format("Hello, %s!", var.name) > format("Hello, %s!", var.name)
Hello, Valentina! Hello, Valentina!
> "Hello, ${var.name}!" > "Hello, ${var.name}!"

View File

@ -28,7 +28,7 @@ once per element of the list arguments.
## Examples ## Examples
```text ```shell-session
> formatlist("Hello, %s!", ["Valentina", "Ander", "Olivia", "Sam"]) > formatlist("Hello, %s!", ["Valentina", "Ander", "Olivia", "Sam"])
[ [
"Hello, Valentina!", "Hello, Valentina!",

View File

@ -21,7 +21,7 @@ indent(num_spaces, string)
This function is useful for inserting a multi-line string into an This function is useful for inserting a multi-line string into an
already-indented context in another string: already-indented context in another string:
```text ```shell-session
> " items: %{indent(2, "[\n foo,\n bar,\n]\n")}" > " items: %{indent(2, "[\n foo,\n bar,\n]\n")}"
items: [ items: [
foo, foo,

View File

@ -18,7 +18,7 @@ join(separator, list)
## Examples ## Examples
```text ```shell-session
> join(", ", ["foo", "bar", "baz"]) > join(", ", ["foo", "bar", "baz"])
foo, bar, baz foo, bar, baz
> join(", ", ["foo"]) > join(", ", ["foo"])

View File

@ -13,7 +13,7 @@ description: >-
## Examples ## Examples
```text ```shell-session
> lower("HELLO") > lower("HELLO")
hello hello
> lower("АЛЛО!") > lower("АЛЛО!")

View File

@ -25,7 +25,7 @@ name of a capture group.
## Examples ## Examples
```text ```shell-session
> regexreplace("hello world", "world", "everybody") > regexreplace("hello world", "world", "everybody")
hello everybody hello everybody

View File

@ -18,7 +18,7 @@ replace(string, substring, replacement)
## Examples ## Examples
```text ```shell-session
> replace("1 + 2 + 3", "+", "-") > replace("1 + 2 + 3", "+", "-")
1 - 2 - 3 1 - 2 - 3

View File

@ -18,7 +18,7 @@ split(separator, string)
## Examples ## Examples
```text ```shell-session
> split(",", "foo,bar,baz") > split(",", "foo,bar,baz")
[ [
"foo", "foo",

View File

@ -16,7 +16,7 @@ strrev(string)
## Examples ## Examples
```text ```shell-session
> strrev("hello") > strrev("hello")
olleh olleh
> strrev("a ☃") > strrev("a ☃")

View File

@ -17,7 +17,7 @@ substr(string, offset, length)
## Examples ## Examples
```text ```shell-session
> substr("hello world", 1, 4) > substr("hello world", 1, 4)
ello ello
``` ```
@ -25,7 +25,7 @@ ello
The offset and length are both counted in _unicode characters_ rather than The offset and length are both counted in _unicode characters_ rather than
bytes: bytes:
```text ```shell-session
> substr("🤔🤷", 0, 1) > substr("🤔🤷", 0, 1)
🤔 🤔
``` ```

View File

@ -13,7 +13,7 @@ description: |-
## Examples ## Examples
```text ```shell-session
> title("hello world") > title("hello world")
Hello World Hello World
``` ```

View File

@ -14,7 +14,7 @@ string.
## Examples ## Examples
```text ```shell-session
> trim("?!hello?!", "!?") > trim("?!hello?!", "!?")
hello hello
``` ```

Some files were not shown because too many files have changed in this diff Show More