Skip to content

Commit

Permalink
Update more CLI texts (#1301)
Browse files Browse the repository at this point in the history
Make #1294 more generic and update more CLI texts.

- Use the `<pre class="log">` approach instead of `log` code fence as it
allows us to style the output more.
- Convert known terminal escape sequences to formats (mainly `<em>`,
`<i>`, `<strong>`).
- Remove the versions numbers from the output as these would produce
diffs for each new version, although the texts have not changed.
- Fix the workflow and produce a PR with a stable title. Parallel PRs
seem unnecessary.
- GH limitation: that PR cannot trigger new workflows. Workaround is to
close and reopen the PR.
  - Example is #1303 

This also gets rid of the [custom renovate config to bump inner-md
versions](https://github.com/cap-js/docs/blob/810cd2beedab1f0d9aa6ae0777c8b79a69f8f067/.github/renovate.json#L58-L117)
and the corresponding PRs.

---------

Co-authored-by: Daniel O'Grady <[email protected]>
  • Loading branch information
chgeo and daogrady authored Oct 2, 2024
1 parent 53b7528 commit e34a80c
Show file tree
Hide file tree
Showing 15 changed files with 275 additions and 245 deletions.
52 changes: 52 additions & 0 deletions .github/cli/grab-cli-texts.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
#!/usr/bin/env node

// CLI Help Extractor
// ============================
// runs "npm exec --package=<tool> -c <cmd>" to extract the command output and version
// of the latest tool version and writes it to stdout

import * as proc from 'node:child_process'
import * as util from 'node:util'

const exec = util.promisify(proc.exec)
const pkg = process.argv[2]
if (!pkg) throw new Error('Missing package')
const cmd = process.argv[3] || pkg.split('/').pop()
const cwd = process.argv[4] || process.cwd()

const toOutput = (str) => [
'<!-- this file is automatically generated and updated by a github action -->',
`<pre class="log">`,
`> ${cmd}`,
'',
str
.replace(/\n.*home.*[|:].*/g, '') // remove absolute cds home path as it's system-specific
.replace(/\<(.*?)\>/g, '&lt;$1&gt;') // <foo> -> &lt;foo&gt;
.replace(/^\x1b\[1m(.*?)\x1b\[(:?0|39|49)m\n/gm, '<strong>$1</strong>') // bold at beginning of line -> strong
.replace(/(\s*)\x1b\[4m(.*?)\x1b\[(:?0|39|49)m/g, '$1<i>$2</i>') // underline -> i
.replace(/(\s*)\x1b\[\d+m(.*?)\x1b\[(:?0|39|49)m/g, '$1<em>$2</em>') // other colors -> em
,
`</pre>`
].join('\n')

try {
const version = (await exec(`npm view ${pkg} version`)).stdout.trim()
if (!/\d+\.\d+\.\d+/.test(version)) {
throw new Error(`unexpected version: ${version}`)
}

const cmdString = `npm exec --package=${pkg}@${version} -c "${cmd}"`
// const cmdString = `${cmd}` // for local testing
console.error(`> ${cmdString}`) // use stderr for debugging output
const { stdout: cmdOut } = await exec(cmdString, {cwd, env: { FORCE_COLOR: 'true', ...process.env }})

// some very basic plausibility checks to make sure we don't
// end up with garbage or npx errors in the markdown
if (!cmdOut || !cmdOut.includes('\n')) {
throw new Error(`no or invalid output from: ${cmdString}`)
}
// result is on stdout
console.log(toOutput(cmdOut.trim(), version.trim()))
} catch (e) {
console.error(`could not generate synopsis: ${e.message}`, e)
}
20 changes: 20 additions & 0 deletions .github/cli/grab-cli-texts.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
#!/usr/bin/env bash

dir=`dirname -- "$0"`

# create a temp project to run the commands in
proj=/tmp/your-project
rm -rf ${proj}
mkdir -p `dirname ${proj}`
pushd `dirname ${proj}` && cds init `basename ${proj}` && pushd `basename ${proj}` && npm i && popd && popd

echo
echo "Grabbing CLI texts..."
${dir}/grab-cli-texts.js @cap-js/cds-typer "cds-typer --help" ${proj} > ${dir}/../../tools/assets/help/cds-typer.out.md
${dir}/grab-cli-texts.js @sap/cds-dk "cds --help" ${proj} > ${dir}/../../tools/assets/help/cds-help.out.md
${dir}/grab-cli-texts.js @sap/cds-dk "cds watch --help" ${proj} > ${dir}/../../tools/assets/help/cds-watch.out.md
${dir}/grab-cli-texts.js @sap/cds-dk "cds version" ${proj} > ${dir}/../../tools/assets/help/cds-version.out.md
${dir}/grab-cli-texts.js @sap/cds-dk "cds version --markdown" ${proj} > ${dir}/../../tools/assets/help/cds-version-md.out.md
${dir}/grab-cli-texts.js @sap/cds-dk "cds env requires.db" ${proj} > ${dir}/../../tools/assets/help/cds-env-requires-db.out.md
${dir}/grab-cli-texts.js @sap/cds-dk "cds env ls requires.db" ${proj} > ${dir}/../../tools/assets/help/cds-env-ls-requires-db.out.md
${dir}/grab-cli-texts.js @sap/cds-dk "cds -e .env.requires.db" ${proj} > ${dir}/../../tools/assets/help/cds-eval-env-requires-db.out.md
60 changes: 0 additions & 60 deletions .github/renovate.json
Original file line number Diff line number Diff line change
Expand Up @@ -54,65 +54,5 @@
"depNameTemplate": "com.sap.cds:cds4j-api",
"datasourceTemplate": "maven",
"versioningTemplate": "maven"
},
{
"customType": "regex",
"fileMatch": ["\\.md$"],
"matchStrings": [
"<em>\\s*@sap/cds:\\s*</em>\\s*(?<currentValue>\\d+\\.\\d+\\.\\d+)",
"\\|\\s*@sap/cds\\s*\\|\\s*(?<currentValue>\\d+\\.\\d+\\.\\d+)\\s*\\|"
],
"depNameTemplate": "@sap/cds",
"datasourceTemplate": "npm"
},
{
"customType": "regex",
"fileMatch": ["\\.md$"],
"matchStrings": [
"<em>\\s*@sap/cds-compiler:\\s*</em>\\s*(?<currentValue>\\d+\\.\\d+\\.\\d+)",
"\\|\\s*@sap/cds-compiler\\s*\\|\\s*(?<currentValue>\\d+\\.\\d+\\.\\d+)\\s*\\|"
],
"depNameTemplate": "@sap/cds-compiler",
"datasourceTemplate": "npm"
},
{
"customType": "regex",
"fileMatch": ["\\.md$"],
"matchStrings": [
"<em>\\s*@sap/cds-dk:\\s*</em>\\s*(?<currentValue>\\d+\\.\\d+\\.\\d+)",
"\\|\\s*@sap/cds-dk\\s*\\|\\s*(?<currentValue>\\d+\\.\\d+\\.\\d+)\\s*\\|"
],
"depNameTemplate": "@sap/cds-dk",
"datasourceTemplate": "npm"
},
{
"customType": "regex",
"fileMatch": ["\\.md$"],
"matchStrings": [
"<em>\\s*@sap/cds-mtxs:\\s*</em>\\s*(?<currentValue>\\d+\\.\\d+\\.\\d+)",
"\\|\\s*@sap/cds-mtxs\\s*\\|\\s*(?<currentValue>\\d+\\.\\d+\\.\\d+)\\s*\\|"
],
"depNameTemplate": "@sap/cds-mtxs",
"datasourceTemplate": "npm"
},
{
"customType": "regex",
"fileMatch": ["\\.md$"],
"matchStrings": [
"<em>\\s*@sap/eslint-plugin-cds:\\s*</em>\\s*(?<currentValue>\\d+\\.\\d+\\.\\d+)",
"\\|\\s*@sap/eslint-plugin-cds\\s*\\|\\s*(?<currentValue>\\d+\\.\\d+\\.\\d+)\\s*\\|"
],
"depNameTemplate": "@sap/eslint-plugin-cds",
"datasourceTemplate": "npm"
},
{
"customType": "regex",
"fileMatch": ["\\.md$"],
"matchStrings": [
"<em>\\s*Node.js:\\s*</em>\\s*(?<currentValue>v\\d+\\.\\d+\\.\\d+)",
"\\|\\s*Node.js\\s*\\|\\s*(?<currentValue>v\\d+\\.\\d+\\.\\d+)\\s*\\|"
],
"depNameTemplate": "nodejs",
"datasourceTemplate": "node"
}
]}
37 changes: 16 additions & 21 deletions .github/workflows/extract-docs.yml
Original file line number Diff line number Diff line change
@@ -1,13 +1,17 @@
name: PR Latest cds-typer Output
name: Update CLI Texts

on:
workflow_dispatch:
schedule:
# Runs every Wednesday at 02:45 AM (UTC)
- cron: '45 2 * * 3'

permissions:
contents: write
pull-requests: write

jobs:
run_script_and_create_pr:
run:
runs-on: ubuntu-latest

steps:
Expand All @@ -19,34 +23,25 @@ jobs:
with:
node-version: '20'

- name: Extract cds-typer --help text
run: node .github/typer/grab-typer-synopsis.js
- name: Extract CLI texts
run: |
npm i -g @sap/cds-dk
.github/cli/grab-cli-texts.sh
- name: Check for changes
run: |
git config --global user.name 'github-actions[bot]'
git config --global user.email 'github-actions[bot]@users.noreply.github.com'
git add -A
if git diff --cached --exit-code; then
if git diff --exit-code; then
echo "No changes detected. Exiting."
exit 0
fi
- name: Commit changes
run: |
git commit -m "Update cds-typer synopsis"
- name: Push changes
run: |
BRANCH_NAME="update-cds-typer-synopsis-$(date +'%Y%m%d%H%M%S')"
git checkout -b "$BRANCH_NAME"
git push origin "$BRANCH_NAME"
- name: Create Pull Request
uses: peter-evans/create-pull-request@v5
uses: peter-evans/create-pull-request@v7
with:
token: ${{ secrets.GITHUB_TOKEN }}
branch: ${{ steps.push_changes.outputs.BRANCH_NAME }}
title: "chore: Update synopsis for cds-typer"
body: "Updates the output of `cds-typer --help` to the latest version."
base: main
branch: "update-cds-cli-texts"
commit-message: "Update CLI texts"
title: "chore: Update CLI texts"
body: "Updates the output of cds CLI texts to the latest version."
35 changes: 10 additions & 25 deletions node.js/cds-env.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,41 +30,26 @@ cds env ? #> get help

For example:

<pre class="log">
<i>$</i> cds env ls requires.sql
requires.sql.credentials.database = <em>:memory:</em>
requires.sql.impl = <em>@sap/cds/lib/db/sql-service</em>
requires.sql.kind = <em>sqlite</em>
</pre>
<!--@include: ../tools/assets/help/cds-env-ls-requires-db.out.md -->

<pre class="log">
<i>$</i> cds env get requires.sql
{
credentials: { database: <em>':memory:'</em> },
impl: <em>'@sap/cds/lib/db/sql-service'</em>,
kind: <em>'sqlite</em>'
}
</pre>
<br>

<!--@include: ../tools/assets/help/cds-env-requires-db.out.md -->


Alternatively, you can also use the `cds eval` or `cds repl` CLI commands to access the `cds.env` property, which provides programmatic access to the effective settings:

<pre class="log">
<i>$</i> cds -e .env.requires.sql
{
credentials: { database: <em>':memory:'</em> },
impl: <em>'@sap/cds/lib/db/sql-service'</em>,
kind: <em>'sqlite'</em>
}
</pre>
<!--@include: ../tools/assets/help/cds-eval-env-requires-db.out.md -->

<br>

<pre class="log">
<i>$</i> cds -r
<em>Welcome to cds repl ...</em>
> cds.env.requires.sql
> cds.env.requires.db
{
credentials: { database: <em>':memory:'</em> },
impl: <em>'@sap/cds/lib/db/sql-service'</em>,
impl: <em>'@cap-js/sqlite'</em>,
credentials: { url: <em>':memory:'</em> },
kind: <em>'sqlite'</em>
}
</pre>
Expand Down
8 changes: 8 additions & 0 deletions tools/assets/help/cds-env-ls-requires-db.out.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<!-- this file is automatically generated and updated by a github action -->
<pre class="log">
> cds env ls requires.db

requires.db.credentials.url = <em>':memory:'</em>
requires.db.impl = <em>'@cap-js/sqlite'</em>
requires.db.kind = <em>'sqlite'</em>
</pre>
10 changes: 10 additions & 0 deletions tools/assets/help/cds-env-requires-db.out.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<!-- this file is automatically generated and updated by a github action -->
<pre class="log">
> cds env requires.db

{
impl: <em>'@cap-js/sqlite'</em>,
credentials: { url: <em>':memory:'</em> },
kind: <em>'sqlite'</em>
}
</pre>
10 changes: 10 additions & 0 deletions tools/assets/help/cds-eval-env-requires-db.out.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<!-- this file is automatically generated and updated by a github action -->
<pre class="log">
> cds -e .env.requires.db

{
impl: <em>'@cap-js/sqlite'</em>,
credentials: { url: <em>':memory:'</em> },
kind: <em>'sqlite'</em>
}
</pre>
39 changes: 39 additions & 0 deletions tools/assets/help/cds-help.out.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
<!-- this file is automatically generated and updated by a github action -->
<pre class="log">
> cds --help

<strong>USAGE</strong>
<em>cds</em> &lt;command&gt; [&lt;args&gt;]
<em>cds</em> &lt;src&gt; = <em>cds compile</em> &lt;src&gt;
<em>cds</em> = <em>cds help</em>

<strong>COMMANDS</strong>
<em>i</em> | <em>init</em> jump-start cds-based projects
<em>a</em> | <em>add</em> add a feature to an existing project
<em> </em> | <em>gen</em> generate models/data using a descriptive prompt [beta]
<em>y</em> | <em>bind</em> bind application to remote services
<em>m</em> | <em>import</em> add models from external sources
<em>c</em> | <em>compile</em> compile cds models to different outputs
<em>p</em> | <em>parse</em> parses given cds models
<em>s</em> | <em>serve</em> run your services in local server
<em>w</em> | <em>watch</em> run and restart on file changes
<em> </em> | <em>mock</em> call <i>cds serve</i> with mocked service
<em>r</em> | <em>repl</em> read-eval-event loop
<em>e</em> | <em>env</em> inspect effective configuration
<em>b</em> | <em>build</em> prepare for deployment
<em>d</em> | <em>deploy</em> deploy to databases or cloud
<em> </em> | <em>subscribe</em> subscribe a tenant to a multitenant SaaS app
<em> </em> | <em>unsubscribe</em> unsubscribe a tenant from a multitenant SaaS app
<em>l</em> | <em>login</em> login to extensible multitenant SaaS app
<em> </em> | <em>logout</em> logout from extensible multitenant SaaS app
<em> </em> | <em>pull</em> pull base model of extensible SaaS app
<em> </em> | <em>push</em> push extension to extensible SaaS app
<em>t</em> | <em>lint</em> run linter for env or model checks
<em>v</em> | <em>version</em> get detailed version information
<em> </em> | <em>completion</em> add/remove cli completion for cds commands
<em>?</em> | <em>help</em> get detailed usage information

Learn more about each command using:
<em>cds help</em> &lt;command&gt; or
<em>cds</em> &lt;command&gt; <em>--help</em>
</pre>
Loading

0 comments on commit e34a80c

Please sign in to comment.