Skip to content

Commit

Permalink
Feb Update
Browse files Browse the repository at this point in the history
  • Loading branch information
jung-thomas committed Feb 3, 2023
1 parent ebba926 commit 70773b0
Show file tree
Hide file tree
Showing 50 changed files with 953 additions and 726 deletions.
13 changes: 13 additions & 0 deletions CHANGELOG.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,17 @@
[
{
"date": "2023-02-03",
"version": "3.202302.1",
"Changed": [
"Lazy Load dependent modules to reduce initial command processor boot time - 10x performance improvement",
"CAP Upgrade to Jan 2023 - 6.5.0 version",
"Switch to @json2csv/node as json2csv is abandoned",
"New 'sub' command to list all active BTP Subscriptions and their URLs",
"New 'btpInfo' command to list detailed information about th btp CLI target",
"New 'issue' command to create GitHub issue preloaded with technical details",
"version command now returns information about @sap/cds-dk, the cf cli, and the btp cli"
]
},
{
"date": "2023-01-17",
"version": "3.202301.1",
Expand Down
12 changes: 12 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,18 @@ All notable changes to this project will be documented in this file.

The format is based on [Keep a Changelog](http://keepachangelog.com/).

## [3.202302.1] - 2023-02-03

**Changed**

- Lazy Load dependent modules to reduce initial command processor boot time - 10x performance improvement
- CAP Upgrade to Jan 2023 - 6.5.0 version
- Switch to @json2csv/node as json2csv is abandoned
- New 'sub' command to list all active BTP Subscriptions and their URLs
- New 'btpInfo' command to list detailed information about th btp CLI target
- New 'issue' command to create GitHub issue preloaded with technical details
- version command now returns information about @sap/cds-dk, the cf cli, and the btp cli

## [3.202301.1] - 2023-01-17

**Changed**
Expand Down
50 changes: 50 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -273,6 +273,25 @@ Options:
![bas example](https://raw.githubusercontent.com/wiki/SAP-samples/hana-developer-cli-tool-example/images/btp.gif)
### btpInfo
```shell
Detailed Information about btp CLI target
Troubleshooting:
--disableVerbose, --quiet Disable Verbose output - removes all extra outp
ut that is only helpful to human readable inter
face. Useful for scripting commands.
[boolean] [default: false]
--debug, --Debug Debug hana-cli itself by adding output of LOTS
of intermediate details
[boolean] [default: false]
Options:
-o, --output, --Output Output Format for inspection
[string] [choices: "tbl", "json"] [default: "tbl"]
```
### callProcedure
```shell
Expand Down Expand Up @@ -1478,6 +1497,20 @@ Options:
ifiers ier] [boolean] [default: false]
```
### issue
```shell
Report an Issue with the hana-cli
Troubleshooting:
--disableVerbose, --quiet Disable Verbose output - removes all extra output t
hat is only helpful to human readable interface. Us
eful for scripting commands.
[boolean] [default: false]
--debug, --Debug Debug hana-cli itself by adding output of LOTS of i
ntermediate details [boolean] [default: false]
```
### libraries
```shell
Expand Down Expand Up @@ -1960,6 +1993,7 @@ Options:
![roles example](https://raw.githubusercontent.com/wiki/SAP-samples/hana-developer-cli-tool-example/images/roles.gif)
### sbss
```shell
hana-cli sbss List all SAP HANA Cloud SBSS service
instances in your target Space
Expand Down Expand Up @@ -2005,6 +2039,7 @@ Options:
--all, --al, --allSchemas Show all schemas regardless of permissions
[boolean] [default: false]
```
![schemas example](https://raw.githubusercontent.com/wiki/SAP-samples/hana-developer-cli-tool-example/images/schemas.gif)
### schemasUI
Expand Down Expand Up @@ -2034,6 +2069,7 @@ Options:
--all, --al, --allSchemas Show all schemas regardless of permissions
[boolean] [default: false]
```
### schemaInstances
```shell
Expand Down Expand Up @@ -2160,6 +2196,20 @@ Options:
![status example](https://raw.githubusercontent.com/wiki/SAP-samples/hana-developer-cli-tool-example/images/status.gif)
### sub
```shell
BTP Active Subscriptions and their URL
Troubleshooting:
--disableVerbose, --quiet Disable Verbose output - removes all extra output t
hat is only helpful to human readable interface. Us
eful for scripting commands.
[boolean] [default: false]
--debug, --Debug Debug hana-cli itself by adding output of LOTS of i
ntermediate details [boolean] [default: false]
```
### synonyms
```shell
Expand Down
10 changes: 9 additions & 1 deletion _i18n/messages.properties
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,9 @@ errorUndefinedAction=Error: Undefined Action
btpCmd=Set the target for commands for the btp CLI to the global account, a directory, or a subaccount. Commands are executed in the specified target, unless you override it using a parameter. If the specified target is part of an account hierarchy, its parents are also targeted, so that if a command is only available on a higher level, it will be executed there.
btpDir=The ID of the directory to be targeted
btpSa=The ID of the subaccount to be targeted
btpSub=BTP Active Subscriptions and their URL
btpGlobal=Global Account
btpInfo=Detailed Information about btp CLI target
log=Processing Log
gui.conn=Connection Parameters
gui.refreshConn=Refresh Connection
Expand Down Expand Up @@ -280,4 +282,10 @@ err.BTPNoTarget=No BTP cli Target found - are you logged in?
err.BTPNoGlobalAccount=No BTP cli Global Account Target Found
err.BTPNoSubAccount=No BTP cli Subaccount Target Found
hc.BTPCheck=Checking at the BTP Level
hc.CFCheck=Checking at the CF Level
hc.CFCheck=Checking at the CF Level
btp.ServerURL=btp CLI server URL
btp.globalaccount=🗺️Global Account
btp.folder=📂Folder
btp.subaccount=🧾Sub Account
btp.version=btp CLI version
issue=Report an Issue with the hana-cli
16 changes: 10 additions & 6 deletions bin/btp.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,6 @@
import * as base from '../utils/base.js'
import * as btp from '../utils/btp.js'
const colors = base.colors
import { createRequire } from 'module'
const require = createRequire(import.meta.url)
const inquirer = require('inquirer')
const TreePrompt = require('inquirer-tree-prompt')


export const command = 'btp [directory] [subaccount]'
export const aliases = ['btpTarget', 'btptarget', 'btp']
Expand All @@ -30,13 +25,20 @@ export async function handler(argv) {
}
}

base.debug(`build inquirer prompts`)
const inquirer = base.require('inquirer')
const TreePrompt = base.require('inquirer-tree-prompt')

try {
base.debug(`GetBTPGlobalAccount`)
base.startSpinnerInt()
var account = await btp.getBTPGlobalAccount()
base.debug(account)
try {
console.log(`${base.bundle.getText("btpGlobal")}: ${colors.green(account.DisplayName)}`)
let hierarchy = await btp.getBTPHierarchy()
base.debug(hierarchy)
base.stopSpinnerInt()
console.log(`${base.bundle.getText("btpGlobal")}: ${colors.green(account.DisplayName)}`)
inquirer.registerPrompt('tree', TreePrompt)

let tree = []
Expand Down Expand Up @@ -96,10 +98,12 @@ export async function handler(argv) {

export async function callBTP(prompts) {
base.debug('callBTP')
base.startSpinnerInt()
base.debug(prompts)
try {
base.setPrompts(prompts)
let targetOutput = await btp.setBTPSubAccount(prompts.subaccount)
base.stopSpinnerInt()
console.log(targetOutput)

return base.end()
Expand Down
63 changes: 63 additions & 0 deletions bin/btpInfo.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
// @ts-check
import * as base from '../utils/base.js'
import * as btp from '../utils/btp.js'
const colors = base.colors

export const command = 'btpInfo'
export const aliases = ['btpinfo']
export const describe = base.bundle.getText("btpInfo")

export const builder = base.getBuilder({
output: {
alias: ['o', 'Output'],
choices: ["tbl", "json"],
default: "tbl",
type: 'string',
desc: base.bundle.getText("outputType")
}
}, false)


export async function handler(argv) {
base.promptHandler(argv, getBTPInfo, {
output: {
description: base.bundle.getText("outputType"),
type: 'string',
// validator: /t[bl]*|s[ql]*|c[ds]?/,
required: true
}
})
}

export async function getBTPInfo(prompts) {
base.debug('getBTPInfo')
base.startSpinnerInt()
base.debug(prompts)
try {
base.setPrompts(prompts)

let data = await btp.getBTPConfig()
base.stopSpinnerInt()
if(prompts.output === 'json'){
console.log(data)
}else{
console.log(`${base.bundle.getText("dbx.user")}: ${colors.green(data.UserName)}`)
console.log(`${base.bundle.getText("btp.ServerURL")}: ${colors.blue(data.ServerURL)}`)
console.log(`${base.bundle.getText("btp.version")}: ${colors.green(data.Version)}`)
for (let item of data.TargetHierarchy) {
let output = ''
if(item.Type === 'globalaccount'){
output = base.bundle.getText("btp.globalaccount")
}else if(item.Type === 'directory'){
output = base.bundle.getText("btp.folder")
}else if(item.Type === 'subaccount'){
output = base.bundle.getText("btp.subaccount")
}
console.log(`${output}: ${colors.green(item.DisplayName)} ${colors.red(item.ID)}`)
}
}
return base.end()
} catch (error) {
base.error(error)
}
}
40 changes: 40 additions & 0 deletions bin/btpSubs.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
// @ts-check
import * as base from '../utils/base.js'
import * as btp from '../utils/btp.js'
const colors = base.colors

export const command = 'sub'
export const aliases = ['subs', 'Sub', 'Subs', 'btpsub', 'btpsubs', 'btpSub', 'btpSubs', 'btpsubscriptions', 'btpSubscriptions']
export const describe = base.bundle.getText("btpSub")

export const builder = base.getBuilder({}, false)


export async function handler(argv) {
base.promptHandler(argv, getSubs, {})
}

export async function getSubs(prompts) {
base.debug('getSubs')
base.startSpinnerInt()
base.debug(prompts)
try {
base.setPrompts(prompts)

let subs = await btp.getBTPSubscriptions()
base.stopSpinnerInt()
const subscribed = 'SUBSCRIBED'
for (let item of subs.applications) {
if (item.state === subscribed) {
console.log(item.displayName)
if (item.subscriptionUrl) {
console.log(colors.blue(item.subscriptionUrl))
}
}
}

return base.end()
} catch (error) {
base.error(error)
}
}
21 changes: 9 additions & 12 deletions bin/cds.js
Original file line number Diff line number Diff line change
@@ -1,17 +1,11 @@
// @ts-check
import * as base from '../utils/base.js'
import * as dbInspect from '../utils/dbInspect.js'
import * as swaggerUi from 'swagger-ui-express'
import open from 'open'
import * as conn from '../utils/connections.js'
import * as Server from 'http'
import express from 'express'

// @ts-ignore
import cds from '@sap/cds'

import { createRequire } from 'module'
const require = createRequire(import.meta.url)

global.__xRef = []

export const command = 'cds [schema] [table]'
Expand Down Expand Up @@ -56,7 +50,7 @@ export const builder = base.getBuilder({
}
})

export function handler(argv) {
export async function handler(argv) {
base.promptHandler(argv, cdsBuild, {
table: {
description: base.bundle.getText("table"),
Expand Down Expand Up @@ -201,13 +195,15 @@ export async function cdsBuild(prompts) {
async function cdsServerSetup(prompts, cdsSource) {

base.debug('cdsServerSetup')
const {default:Server} = await import('http')
const port = process.env.PORT || prompts.port || 3010

if (!(/^[1-9]\d*$/.test(port) && 1 <= 1 * port && 1 * port <= 65535)) {
return base.error(`${port} ${base.bundle.getText("errPort")}`)
}

const server = Server.createServer()
const express = base.require('express')
var app = express()

//CDS OData Service
Expand Down Expand Up @@ -336,7 +332,7 @@ async function cdsServerSetup(prompts, cdsSource) {

//Swagger UI

Object.defineProperty(cds.compile.to, 'openapi', { configurable: true, get: () => require('@sap/cds-dk/lib/compile/openapi') })
Object.defineProperty(cds.compile.to, 'openapi', { configurable: true, get: () => base.require('@sap/cds-dk/lib/compile/openapi') })
try {
// @ts-ignore
let metadata = await cds.compile.to.openapi(cds.parse(cdsSource), {
Expand All @@ -349,6 +345,7 @@ async function cdsServerSetup(prompts, cdsSource) {
let serveOptions = {
explorer: true
}
const swaggerUi = await import('swagger-ui-express')
app.use('/api/api-docs', swaggerUi.serve, swaggerUi.setup(metadata, serveOptions))

app.get('/', (_, res) => res.send(getIndex(odataURL, entity)))
Expand All @@ -370,18 +367,18 @@ async function cdsServerSetup(prompts, cdsSource) {

//Start the Server
server.on("request", app)
server.listen(port, function () {
server.listen(port, async () => {
// @ts-ignore
let serverAddr = `http://localhost:${server.address().port}`
console.info(`HTTP Server: ${serverAddr}`)

//GraphQL
const GraphQLAdapter = require('@cap-js/graphql/lib') //require('@sap/cds-graphql/lib')
const GraphQLAdapter = base.require('@cap-js/graphql/lib') //require('@sap/cds-graphql/lib')
const adapter = new GraphQLAdapter (cds.services, { graphiql: true, path: '/graphql' })
app.use('/graphql', adapter)
// app.use(new GraphQLAdapter(cds.services, { graphiql: true }))
console.log("serving GraphQL endpoint for all services { at: '/graphql' }")

const { default:open } = await import('open')
open(serverAddr)
})
}
Expand Down
Loading

0 comments on commit 70773b0

Please sign in to comment.