generated from salesforcecli/plugin-template
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1 from salesforcecli/wr/addCommands
fix: initial schema commands move
- Loading branch information
Showing
14 changed files
with
1,475 additions
and
1,325 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,25 +1,6 @@ | ||
# plugin-<REPLACE ME> | ||
# plugin-schema | ||
|
||
Change above to <REPLACE_ME> before finalizing | ||
|
||
<REPLACE ME DESCRIPTION START> | ||
|
||
This repository provides a template for creating a plugin for the Salesforce CLI. To convert this template to a working plugin: | ||
|
||
1. Clone this repo | ||
2. Delete the .git folder | ||
3. Replace filler values | ||
a) Every instance of `<REPLACE_ME>` can be directly substitued for the name of the new plugin. However beware, things like github paths are for the salesforcecli Github organization | ||
b) Search for case-matching `REPLACE` to find other filler values, such as for the plugin description | ||
4. Use `git init` to set up the desired git information | ||
5. Follow the getting started steps below until the `sfdx hello:org` commmand is functioning | ||
6. In order to prevent build failures on the intial build, you will need to do the following: | ||
1. `npm publish` | ||
2. `git tag v1.0.0 ; git push origin v1.0.0` | ||
|
||
<REPLACE ME DESCRIPTION END> | ||
|
||
### Everything past here is only a suggestion as to what should be in your specific plugin's descsription. | ||
Commands to interact with salesforce sobject schemas | ||
|
||
## Getting Started | ||
|
||
|
@@ -28,8 +9,8 @@ To use, install the [Salesforce CLI](https://developer.salesforce.com/tools/sfdx | |
``` | ||
Verify the CLI is installed | ||
$ sfdx (-v | --version) | ||
Install the <REPLACE_ME> plugin | ||
$ sfdx plugins:install <REPLACE_ME> | ||
Install the @salesforce/plugin-schema plugin | ||
$ sfdx plugins:install @salesforce/plugin-schema | ||
To run a command | ||
$ sfdx [command] | ||
``` | ||
|
@@ -38,7 +19,7 @@ To build the plugin locally, make sure to have yarn installed and run the follow | |
|
||
``` | ||
Clone the repository | ||
$ git clone [email protected]:salesforcecli/plugin-<REPLACE_ME> | ||
$ git clone [email protected]:salesforcecli/plugin-schema | ||
Install the dependencies and compile | ||
$ yarn install | ||
$ yarn prepack | ||
|
@@ -48,32 +29,6 @@ To verify | |
$ sfdx plugins | ||
``` | ||
|
||
## Debugging your plugin | ||
|
||
We recommend using the Visual Studio Code (VS Code) IDE for your plugin development. Included in the `.vscode` directory of this plugin is a `launch.json` config file, which allows you to attach a debugger to the node process when running your commands. | ||
|
||
To debug the `hello:org` command: | ||
|
||
If you linked your plugin to the sfdx cli, call your command with the `dev-suspend` switch: | ||
|
||
```sh-session | ||
$ sfdx hello:org -u [email protected] --dev-suspend | ||
``` | ||
|
||
Alternatively, to call your command using the `bin/run` script, set the `NODE_OPTIONS` environment variable to `--inspect-brk` when starting the debugger: | ||
|
||
```sh-session | ||
$ NODE_OPTIONS=--inspect-brk bin/run hello:org -u [email protected] | ||
``` | ||
|
||
2. Set some breakpoints in your command code | ||
3. Click on the Debug icon in the Activity Bar on the side of VS Code to open up the Debug view. | ||
4. In the upper left hand corner of VS Code, verify that the "Attach to Remote" launch configuration has been chosen. | ||
5. Hit the green play button to the left of the "Attach to Remote" launch configuration window. The debugger should now be suspended on the first line of the program. | ||
6. Hit the green play button at the top middle of VS Code (this play button will be to the right of the play button that you clicked in step #5). | ||
<br><img src=".images/vscodeScreenshot.png" width="480" height="278"><br> | ||
Congrats, you are debugging! | ||
|
||
## Commands | ||
|
||
- [`sfdx hello:org [-n <string>] [-f] [-v <string>] [-u <string>] [--apiversion <string>] [--json] [--loglevel trace|debug|info|warn|error|fatal|TRACE|DEBUG|INFO|WARN|ERROR|FATAL]`](#sfdx-helloorg--n-string--f--v-string--u-string---apiversion-string---json---loglevel-tracedebuginfowarnerrorfataltracedebuginfowarnerrorfatal) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
{ | ||
"description": "displays the metadata for a standard or custom object", | ||
"examples": [ | ||
"sfdx force:schema:sobject:describe -s Account", | ||
"sfdx force:schema:sobject:describe -s MyObject__c", | ||
"sfdx force:schema:sobject:describe -s ApexClass -t" | ||
], | ||
"flags": { | ||
"objectType": "the API name of the object to describe", | ||
"useTooling": "execute with Tooling API" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
{ | ||
"description": "list all objects of a specified category", | ||
"flags": { | ||
"typeDescription": "the type of objects to list (all|custom|standard)", | ||
"invalidTypeError": "\"Type\" flag can be set only to <all|custom|standard>." | ||
}, | ||
"examples": [ | ||
"sfdx force:schema:sobject:list -c all", | ||
"sfdx force:schema:sobject:list -c custom", | ||
"sfdx force:schema:sobject:list -c standard" | ||
], | ||
"noTypeFound": "No %s objects found." | ||
} |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
/* | ||
* Copyright (c) 2020, salesforce.com, inc. | ||
* All rights reserved. | ||
* Licensed under the BSD 3-Clause license. | ||
* For full license text, see LICENSE.txt file in the repo root or https://opensource.org/licenses/BSD-3-Clause | ||
*/ | ||
|
||
import * as os from 'os'; | ||
import { flags, FlagsConfig, SfdxCommand } from '@salesforce/command'; | ||
import { Connection, Messages } from '@salesforce/core'; | ||
import { DescribeSObjectResult } from 'jsforce'; | ||
|
||
Messages.importMessagesDirectory(__dirname); | ||
const messages = Messages.loadMessages('@salesforce/plugin-schema', 'describe'); | ||
|
||
export class SchemaSObjectDescribe extends SfdxCommand { | ||
public static readonly description = messages.getMessage('description'); | ||
public static readonly examples = messages.getMessage('examples').split(os.EOL); | ||
public static readonly flagsConfig: FlagsConfig = { | ||
sobjecttype: flags.string({ | ||
char: 's', | ||
required: true, | ||
description: messages.getMessage('flags.objectType'), | ||
}), | ||
usetoolingapi: flags.boolean({ | ||
char: 't', | ||
description: messages.getMessage('flags.useTooling'), | ||
}), | ||
}; | ||
|
||
public static readonly requiresUsername = true; | ||
public async run(): Promise<DescribeSObjectResult> { | ||
const conn: Connection = this.org.getConnection(); | ||
const description: DescribeSObjectResult = this.flags.usetoolingapi | ||
? await conn.tooling.describe(this.flags.sobjecttype) | ||
: await conn.describe(this.flags.sobjecttype); | ||
|
||
if (!this.flags.json) { | ||
this.ux.logJson(description); | ||
} | ||
|
||
return description; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
/* | ||
* Copyright (c) 2020, salesforce.com, inc. | ||
* All rights reserved. | ||
* Licensed under the BSD 3-Clause license. | ||
* For full license text, see LICENSE.txt file in the repo root or https://opensource.org/licenses/BSD-3-Clause | ||
*/ | ||
import * as os from 'os'; | ||
import { flags, FlagsConfig, SfdxCommand } from '@salesforce/command'; | ||
import { Connection, Messages, SfdxError } from '@salesforce/core'; | ||
import { DescribeGlobalSObjectResult, DescribeGlobalResult } from 'jsforce'; | ||
|
||
Messages.importMessagesDirectory(__dirname); | ||
const messages = Messages.loadMessages('@salesforce/plugin-schema', 'list'); | ||
|
||
export enum Type { | ||
ALL, | ||
STANDARD, | ||
CUSTOM, | ||
} | ||
|
||
export class SchemaSobjectList extends SfdxCommand { | ||
public static readonly description = messages.getMessage('description'); | ||
public static readonly examples = messages.getMessage('examples').split(os.EOL); | ||
public static readonly flagsConfig: FlagsConfig = { | ||
sobjecttypecategory: flags.string({ | ||
char: 'c', | ||
default: 'ALL', | ||
validate: (val) => { | ||
const capitalized = val.toUpperCase(); | ||
const result = capitalized === 'ALL' || capitalized === 'STANDARD' || capitalized === 'CUSTOM'; | ||
if (!result) { | ||
throw SfdxError.create('@salesforce/plugin-schema', 'list', 'flags.invalidTypeError'); | ||
} | ||
return result; | ||
}, | ||
description: messages.getMessage('flags.typeDescription'), | ||
}), | ||
}; | ||
public static readonly requiresUsername = true; | ||
|
||
public async run(): Promise<string[]> { | ||
let type = this.flags.sobjecttypecategory; | ||
|
||
type = Type[type.toUpperCase()]; | ||
|
||
const typeDescriptions: string[] = []; | ||
|
||
const conn: Connection = this.org.getConnection(); | ||
const allDescriptions: DescribeGlobalResult = await conn.describeGlobal(); | ||
|
||
let havePrinted = false; | ||
|
||
allDescriptions.sobjects.forEach((sobject: DescribeGlobalSObjectResult) => { | ||
const isCustom = sobject.custom === true; | ||
const doPrint = type === Type.ALL || (type === Type.CUSTOM && isCustom) || (type === Type.STANDARD && !isCustom); | ||
if (doPrint) { | ||
havePrinted = true; | ||
this.ux.log(sobject.name); | ||
typeDescriptions.push(sobject.name); | ||
} | ||
}); | ||
|
||
if (!havePrinted) { | ||
this.ux.log(messages.getMessage('noTypeFound', [Type[type]])); | ||
} | ||
|
||
return typeDescriptions; | ||
} | ||
} |
Oops, something went wrong.