diff --git a/.gitignore b/.gitignore index 20c6c1f27..e7cd5ba0d 100644 --- a/.gitignore +++ b/.gitignore @@ -110,3 +110,7 @@ dist # TernJS port file .tern-port + +# IntelliJ files +*.iml +.idea/ diff --git a/messages/rule.json b/messages/rule.json new file mode 100644 index 000000000..45e56f634 --- /dev/null +++ b/messages/rule.json @@ -0,0 +1,42 @@ +{ + "activate": { + "commandDescription": "[Description of 'activate' command]", + "flags": { + "rulenameDescription": "[Description of 'rulename' parameter]" + } + }, + "deactivate": { + "commandDescription": "[Description of 'deactivate' command]", + "flags": { + "rulenameDescription": "[Description of 'rulename' parameter]" + } + }, + "describe": { + "commandDescription": "[Description of 'describe' command]", + "flags": { + "rulenameDescription": "[Description of 'rulename' parameter]" + } + }, + "create": { + "commandDescription": "[Description of 'create' command]", + "flags": { + "rulenameDescription": "[Description of 'rulename' parameter]", + "typeDescription": "[Description of 'type' parameter]", + "severityDescription": "[Description of 'severity' parameter]", + "languagesDescription": "[Description of 'languages' parameter]", + "originalDescription": "[Description of 'original' parameter]" + } + }, + "list": { + "commandDescription": "[Description of 'list' command]", + "flags": { + "languagesDescription": "[Description of 'languages' parameter]", + "typeDescription": "[Description of 'type' parameter]", + "severityDescription": "[Description of 'severity' parameter]", + "standardDescription": "[Description of 'standard' parameter]", + "customDescription": "[Description of 'custom' parameter]", + "activeDescription": "[Description of 'active' parameter]", + "inactiveDescription": "[Description of 'inactive' parameter]" + } + } +} diff --git a/package.json b/package.json index 8c780beb2..e6fec6a20 100644 --- a/package.json +++ b/package.json @@ -49,6 +49,14 @@ "topics": { "hello": { "description": "Commands to say hello." + }, + "scanner": { + "description": "[Description of scanner plugin goes here]", + "subtopics": { + "rule": { + "description": "[Description of 'rule' subtopic goes here]" + } + } } }, "devPlugins": [ diff --git a/src/commands/scanner/rule/activate.ts b/src/commands/scanner/rule/activate.ts new file mode 100644 index 000000000..a8b05ca16 --- /dev/null +++ b/src/commands/scanner/rule/activate.ts @@ -0,0 +1,59 @@ +import { flags, SfdxCommand } from '@salesforce/command'; +import { Messages, SfdxError } from '@salesforce/core'; +import { AnyJson } from '@salesforce/ts-types'; + +// Initialize Messages with the current plugin directory +Messages.importMessagesDirectory(__dirname); + +// Load the specific messages for this file. Messages from @salesforce/command, @salesforce/core, +// or any library that is using the messages framework can also be loaded this way. +const messages = Messages.loadMessages('scanner', 'rule'); + +export default class Activate extends SfdxCommand { + + public static description = messages.getMessage('activate.commandDescription'); + + public static examples = [ + `$ sfdx hello:org --targetusername myOrg@example.com --targetdevhubusername devhub@org.com + Hello world! This is org: MyOrg and I will be around until Tue Mar 20 2018! + My hub org id is: 00Dxx000000001234 + `, + `$ sfdx hello:org --name myname --targetusername myOrg@example.com + Hello myname! This is org: MyOrg and I will be around until Tue Mar 20 2018! + ` + ]; + + public static args = [{name: 'file'}]; + + protected static flagsConfig = { + // flag with a value (-n, --name=VALUE) + rulename: flags.string({ + char: 'n', + description: messages.getMessage('activate.flags.rulenameDescription'), + required: true + }) + }; + + private performActivation(name: String) : Promise { + return new Promise((res, rej) => { + setTimeout(() => { + res(name === 'passingval'); + }, 2500); + }); + } + + public async run(): Promise { + const rulename = this.flags.rulename; + this.ux.log("Preparing to activate this rule: '" + rulename + "'. Here's hoping that works out for you."); + + let ruleState; + if (await this.performActivation(rulename)) { + this.ux.log("Successfully activated rule: '" + rulename + "'. I'm glad that worked out so well for you."); + ruleState = 'active'; + } else { + this.ux.log("Failed to activate rule: '" + rulename + "'. Sucks to suck."); + ruleState = 'inactive'; + } + return {rulestate: ruleState}; + } +} diff --git a/src/commands/scanner/rule/create.ts b/src/commands/scanner/rule/create.ts new file mode 100644 index 000000000..caa7620b3 --- /dev/null +++ b/src/commands/scanner/rule/create.ts @@ -0,0 +1,56 @@ +import { flags, SfdxCommand } from '@salesforce/command'; +import { Messages, SfdxError } from '@salesforce/core'; +import { AnyJson } from '@salesforce/ts-types'; + +// Initialize Messages with the current plugin directory +Messages.importMessagesDirectory(__dirname); + +// Load the specific messages for this file. Messages from @salesforce/command, @salesforce/core, +// or any library that is using the messages framework can also be loaded this way. +const messages = Messages.loadMessages('scanner', 'rule'); + +export default class Create extends SfdxCommand { + + public static description = messages.getMessage('create.commandDescription'); + + public static examples = [ + `$ sfdx hello:org --targetusername myOrg@example.com --targetdevhubusername devhub@org.com + Hello world! This is org: MyOrg and I will be around until Tue Mar 20 2018! + My hub org id is: 00Dxx000000001234 + `, + `$ sfdx hello:org --name myname --targetusername myOrg@example.com + Hello myname! This is org: MyOrg and I will be around until Tue Mar 20 2018! + ` + ]; + + public static args = [{name: 'file'}]; + + protected static flagsConfig = { + // flag with a value (-n, --name=VALUE) + rulename: flags.string({ + char: 'n', + description: messages.getMessage('create.flags.rulenameDescription'), + required: true + }), + type: flags.string({ + char: 't', + description: messages.getMessage('create.flags.typeDescription') + }), + severity: flags.string({ + char: 's', + description: messages.getMessage('create.flags.severityDescription') + }), + languages: flags.array({ + char: 'l', + description: messages.getMessage('create.flags.languagesDescription') + }), + original: flags.filepath({ + char: 'o', + description: messages.getMessage('create.flags.originalDescription') + }) + }; + + public async run(): Promise { + return {}; + } +} diff --git a/src/commands/scanner/rule/deactivate.ts b/src/commands/scanner/rule/deactivate.ts new file mode 100644 index 000000000..cb4f2a039 --- /dev/null +++ b/src/commands/scanner/rule/deactivate.ts @@ -0,0 +1,59 @@ +import { flags, SfdxCommand } from '@salesforce/command'; +import { Messages, SfdxError } from '@salesforce/core'; +import { AnyJson } from '@salesforce/ts-types'; + +// Initialize Messages with the current plugin directory +Messages.importMessagesDirectory(__dirname); + +// Load the specific messages for this file. Messages from @salesforce/command, @salesforce/core, +// or any library that is using the messages framework can also be loaded this way. +const messages = Messages.loadMessages('scanner', 'rule'); + +export default class Deactivate extends SfdxCommand { + + public static description = messages.getMessage('deactivate.commandDescription'); + + public static examples = [ + `$ sfdx hello:org --targetusername myOrg@example.com --targetdevhubusername devhub@org.com + Hello world! This is org: MyOrg and I will be around until Tue Mar 20 2018! + My hub org id is: 00Dxx000000001234 + `, + `$ sfdx hello:org --name myname --targetusername myOrg@example.com + Hello myname! This is org: MyOrg and I will be around until Tue Mar 20 2018! + ` + ]; + + public static args = [{name: 'file'}]; + + protected static flagsConfig = { + // flag with a value (-n, --name=VALUE) + rulename: flags.string({ + char: 'n', + description: messages.getMessage('deactivate.flags.rulenameDescription'), + required: true + }) + }; + + private performDeactivation(name: String) : Promise { + return new Promise((res, rej) => { + setTimeout(() => { + res(name === 'passingval'); + }, 2500); + }); + } + + public async run(): Promise { + const rulename = this.flags.rulename; + this.ux.log("Preparing to deactivate this rule: '" + rulename + "'. Here's hoping that works out for you."); + + let ruleState; + if (await this.performDeactivation(rulename)) { + this.ux.log("Successfully deactivated rule: '" + rulename + "'. I'm glad that worked out so well for you."); + ruleState = 'inactive'; + } else { + this.ux.log("Failed to deactivate rule: '" + rulename + "'. Sucks to suck."); + ruleState = 'active'; + } + return {rulestate: ruleState}; + } +} diff --git a/src/commands/scanner/rule/describe.ts b/src/commands/scanner/rule/describe.ts new file mode 100644 index 000000000..6241bdfa3 --- /dev/null +++ b/src/commands/scanner/rule/describe.ts @@ -0,0 +1,40 @@ +import { flags, SfdxCommand } from '@salesforce/command'; +import { Messages, SfdxError } from '@salesforce/core'; +import { AnyJson } from '@salesforce/ts-types'; + +// Initialize Messages with the current plugin directory +Messages.importMessagesDirectory(__dirname); + +// Load the specific messages for this file. Messages from @salesforce/command, @salesforce/core, +// or any library that is using the messages framework can also be loaded this way. +const messages = Messages.loadMessages('scanner', 'rule'); + +export default class Describe extends SfdxCommand { + + public static description = messages.getMessage('describe.commandDescription'); + + public static examples = [ + `$ sfdx hello:org --targetusername myOrg@example.com --targetdevhubusername devhub@org.com + Hello world! This is org: MyOrg and I will be around until Tue Mar 20 2018! + My hub org id is: 00Dxx000000001234 + `, + `$ sfdx hello:org --name myname --targetusername myOrg@example.com + Hello myname! This is org: MyOrg and I will be around until Tue Mar 20 2018! + ` + ]; + + public static args = [{name: 'file'}]; + + protected static flagsConfig = { + // flag with a value (-n, --name=VALUE) + rulename: flags.string({ + char: 'n', + description: messages.getMessage('describe.flags.rulenameDescription'), + required: true + }) + }; + + public async run(): Promise { + return {}; + } +} diff --git a/src/commands/scanner/rule/list.ts b/src/commands/scanner/rule/list.ts new file mode 100644 index 000000000..aaa3ebcbf --- /dev/null +++ b/src/commands/scanner/rule/list.ts @@ -0,0 +1,63 @@ +import { flags, SfdxCommand } from '@salesforce/command'; +import { Messages, SfdxError } from '@salesforce/core'; +import { AnyJson } from '@salesforce/ts-types'; + +// Initialize Messages with the current plugin directory +Messages.importMessagesDirectory(__dirname); + +// Load the specific messages for this file. Messages from @salesforce/command, @salesforce/core, +// or any library that is using the messages framework can also be loaded this way. +const messages = Messages.loadMessages('scanner', 'rule'); + +export default class List extends SfdxCommand { + + public static description = messages.getMessage('list.commandDescription'); + + public static examples = [ + `$ sfdx hello:org --targetusername myOrg@example.com --targetdevhubusername devhub@org.com + Hello world! This is org: MyOrg and I will be around until Tue Mar 20 2018! + My hub org id is: 00Dxx000000001234 + `, + `$ sfdx hello:org --name myname --targetusername myOrg@example.com + Hello myname! This is org: MyOrg and I will be around until Tue Mar 20 2018! + ` + ]; + + public static args = [{name: 'file'}]; + + protected static flagsConfig = { + // flag with a value (-n, --name=VALUE) + type: flags.string({ + char: 't', + description: messages.getMessage('list.flags.typeDescription') + }), + severity: flags.string({ + char: 's', + description: messages.getMessage('list.flags.severityDescription') + }), + languages: flags.array({ + char: 'l', + description: messages.getMessage('list.flags.languagesDescription') + }), + standard: flags.boolean({ + char: 'd', + description: messages.getMessage('list.flags.standardDescription') + }), + custom: flags.boolean({ + char: 'c', + description: messages.getMessage('list.flags.customDescription') + }), + active: flags.boolean({ + char: 'a', + description: messages.getMessage('list.flags.activeDescription') + }), + inactive: flags.boolean({ + char: 'i', + description: messages.getMessage('list.flags.inactiveDescription') + }), + }; + + public async run(): Promise { + return {}; + } +}