Skip to content

Commit

Permalink
Merge pull request #1 from salesforcecli/wr/addCommands
Browse files Browse the repository at this point in the history
fix: initial schema commands move
  • Loading branch information
WillieRuemmele authored Oct 29, 2020
2 parents 8ed5c99 + ccd3a9d commit b5ca2ec
Show file tree
Hide file tree
Showing 14 changed files with 1,475 additions and 1,325 deletions.
55 changes: 5 additions & 50 deletions README.md
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

&lt;REPLACE ME DESCRIPTION START&gt;

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`

&lt;REPLACE ME DESCRIPTION END&gt;

### 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

Expand All @@ -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]
```
Expand All @@ -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
Expand All @@ -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)
Expand Down
12 changes: 12 additions & 0 deletions messages/describe.json
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"
}
}
13 changes: 13 additions & 0 deletions messages/list.json
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."
}
22 changes: 0 additions & 22 deletions messages/messages.json

This file was deleted.

6 changes: 0 additions & 6 deletions messages/org.json

This file was deleted.

20 changes: 13 additions & 7 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
{
"name": "@salesforce/plugin-template",
"description": "A template repository for sfdx plugins",
"name": "@salesforce/plugin-schema",
"description": "Commands to interact with salesforce sobject schemas",
"version": "1.0.0",
"author": "Salesforce",
"bugs": "https://github.com/forcedotcom/cli/issues",
"dependencies": {
"@oclif/config": "^1",
"@salesforce/command": "^3.0.3",
"@salesforce/core": "^2.6.0",
"@salesforce/core": "^2.14.0",
"tslib": "^1"
},
"devDependencies": {
Expand Down Expand Up @@ -53,7 +53,7 @@
"/messages",
"/oclif.manifest.json"
],
"homepage": "https://github.com/salesforcecli/plugin-template",
"homepage": "https://github.com/salesforcecli/plugin-schema",
"keywords": [
"force",
"salesforce",
Expand All @@ -69,12 +69,18 @@
"@oclif/plugin-help"
],
"topics": {
"hello": {
"description": "Commands to say hello."
"schema": {
"description": "List metadata types in your Salesforce org using the CLI",
"longDescription": "Use the schema commands to to list metadata types within your Salesforce org using the Salesforce CLI.",
"subtopics": {
"sobject": {
"description": "list standard object metadata types"
}
}
}
}
},
"repository": "salesforcecli/plugin-template",
"repository": "salesforcecli/plugin-schema",
"scripts": {
"build": "sf-build",
"clean": "sf-clean",
Expand Down
44 changes: 44 additions & 0 deletions src/commands/force/schema/sobject/describe.ts
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;
}
}
69 changes: 69 additions & 0 deletions src/commands/force/schema/sobject/list.ts
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;
}
}
Loading

0 comments on commit b5ca2ec

Please sign in to comment.