Skip to content

Commit

Permalink
Merge pull request #24 from devsapp/docs
Browse files Browse the repository at this point in the history
docs: update build help info & docs
  • Loading branch information
wss-git authored Jun 16, 2021
2 parents 394bd66 + 4dfe568 commit 6f30f41
Show file tree
Hide file tree
Showing 8 changed files with 213 additions and 57 deletions.
3 changes: 1 addition & 2 deletions docs/Usage/build.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,7 @@ Options
Global Options
-y, --assume-yes Assume that the answer to any question which would be asked is yes.
-h, --help Display help for command.
-h, --help Build help for command.
Examples with Yaml
Expand Down
28 changes: 14 additions & 14 deletions docs/Usage/invoke.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,14 +29,13 @@ Usage
Options
--t, --invocation-type string Invocation type: optional value "async"|"sync", default value "sync"
(default: "sync")
--e, --event string Event data (strings) passed to the function during invocation (default: "")
--f, --event-file string A file containing event data passed to the function during invoke. You can get the format of different events through [https://help.aliyun.com/document_detail/70140.html], or get help through [s cli fc-event -h], and quickly create the template of the corresponding event format
--s, --event-stdin Read from standard input, to support script pipeline.
--region string Specify the region parameter
--service-name string Specify the service name parameter
--function-name string Specify the function name parameter
-t, --invocation-type string Invocation type: optional value "async"|"sync", default value "sync" (default: "sync")
-e, --event string Event data (strings) passed to the function during invocation (default: "").Http function format refers to [https://github.com/devsapp/fc-remote-invoke#特别说明]
-f, --event-file string Event funtion: A file containing event data passed to the function during invoke. Http function: A file containing http request options sent to http trigger. Format refers to [https://github.com/devsapp/fc-remote-invoke#特别说明]
-s, --event-stdin Read from standard input, to support script pipeline.Http function format refers to [https://github.com/devsapp/fc-remote-invoke#特别说明]
--region string Specify region in cli mode
--service-name string Specify service name in cli mode
--function-name string Specify function name in cli mode
Global Options
Expand All @@ -47,15 +46,16 @@ Examples with Yaml
$ s invoke
$ s <ProjectName> invoke
$ s invoke --region cn-hangzhou --service-name myService --function-name myFunction
$ s exec -- invoke --region cn-hangzhou --service-name myService --function-name myFunction
$ s exec -- invoke --invocation-type sync --event <payload>
$ s exec -- invoke --event-file <file-path>
$ s exec -- invoke --event-stdin
Examples with CLI
$ s cli fc invoke --region cn-hangzhou --service-name myService --function-name myFunction
You also can refer to the usage of fc-api and execute [s cli fc-api -h] for help.
$ s cli fc-api invokeFunction -h
$ s cli fc invoke --region cn-hangzhou --service-name myService --function-name myFunction --event <payload>
$ s cli fc invoke --region cn-hangzhou --service-name myService --function-name myFunction --event-file <file-path>
$ s cli fc invoke --region cn-hangzhou --service-name myService --function-name myFunction --event-stdin
You also can refer to the usage of fc-api and execute [s cli fc-api -h] for help. $ s cli fc-api invokeFunction -h
```

Expand Down
12 changes: 6 additions & 6 deletions docs/Usage/logs.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,15 +29,15 @@ Usage
Options
-t, --tail Real-time query log
-s, --start-time number Query log start time (Timestamp or time format,like 1611827290000 or 2021-11-11T11:11:12+00:00)
-e, --end-time number Query log end time (Timestamp or time format,like 1611827290000 or 2021-11-11T11:11:12+00:00)
-t, --tail Continuous log output mode
-s, --start-time string Query log start time (Timestamp or time format,like 1611827290000 or 2021-11-11T11:11:12+00:00)
-e, --end-time string Query log end time (Timestamp or time format,like 1611827290000 or 2021-11-11T11:11:12+00:00)
-k, --keyword string Keyword query
-r, --request-id string Query according to requestId within the time interval
--type string Log type query, value: failed
--region string Specify the region parameter
--service-name string Specify the service name parameter
--function-name string Specify the function name parameter
--region string Specify region in cli mode
--service-name string Specify service name in cli mode
--function-name string Specify function name in cli mode
Global Options
Expand Down
4 changes: 2 additions & 2 deletions docs/Usage/nas.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ Nas
Usage
$ s nas <sub-command>
$ s nas download <options> <fc_dir> <src_path>
SubCommand:
Expand Down Expand Up @@ -65,7 +65,7 @@ Nas命令为我们提供了三个子命令:
Usage
$ s nas upload <src_path> <fc_dir> <options>
$ s nas upload <options> <src_path> <fc_dir>
Options
Expand Down
2 changes: 1 addition & 1 deletion docs/Usage/sync.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ Examples with Yaml
Examples with CLI
$ s cli fc sync --region * --service-name * --type all
$ s cli fc sync --region cn-shanghai --service-name myService --type config
```

Expand Down
54 changes: 27 additions & 27 deletions src/index.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import * as core from '@serverless-devs/core';
import * as _ from 'lodash';
import { COMPONENT_HELP_INFO, LOCAL_HELP_INFO, LOGS_HELP_INFO, NAS_HELP_INFO,
NAS_SUB_COMMAND_HELP_INFO, INVOKE_HELP_INFO, LOCAL_INVOKE_HELP_INFO, LOCAL_START_HELP_INFO } from './lib/static';
import { COMPONENT_HELP_INFO, LOCAL_HELP_INFO, LOGS_HELP_INFO, NAS_HELP_INFO, METRICS_HELP_INFO,
NAS_SUB_COMMAND_HELP_INFO, INVOKE_HELP_INFO, LOCAL_INVOKE_HELP_INFO, LOCAL_START_HELP_INFO, BUILD_HELP_INFO } from './lib/static';
import tarnsformNas from './lib/tarnsform-nas';
import { ICredentials } from './lib/interface/profile';
import { IInputs, IProperties } from './lib/interface/interface';
Expand All @@ -10,14 +10,15 @@ import { FcInfoProps } from './lib/interface/component/fc-info';
import { FcSyncProps } from './lib/interface/component/fc-sync';
import { FcMetricsProps } from './lib/interface/component/fc-metrics';
import { LogsProps } from './lib/interface/component/logs';
import { getFcNames } from './lib/utils';
import * as tips from './lib/tips';

const SUPPORTED_LOCAL_METHOD: string[] = ['invoke', 'start'];
export default class FcBaseComponent {
@core.HLogger('FC') logger: core.ILogger;

// 解析入参
handlerInputs(inputs: IInputs): any {
private handlerInputs(inputs: IInputs): any {
const project = inputs?.project;
const props: IProperties = inputs?.props;
const access: string = project?.access;
Expand All @@ -35,7 +36,7 @@ export default class FcBaseComponent {
curPath,
};
}
async report(componentName: string, command: string, accountID?: string, access?: string): Promise<void> {
private async report(componentName: string, command: string, accountID?: string, access?: string): Promise<void> {
let uid: string = accountID;
if (_.isEmpty(accountID)) {
const credentials: ICredentials = await core.getCredential(access);
Expand All @@ -47,7 +48,7 @@ export default class FcBaseComponent {
uid,
});
}
handlerComponentInputs(inputs: IInputs, componentName?: string): any {
private handlerComponentInputs(inputs: IInputs, componentName?: string): any {
const {
appName,
projectName,
Expand All @@ -69,7 +70,7 @@ export default class FcBaseComponent {
};
}

async componentMethodCaller(inputs: IInputs, componentName: string, methodName: string, props: any, args: string): Promise<any> {
private async componentMethodCaller(inputs: IInputs, componentName: string, methodName: string, props: any, args: string): Promise<any> {
const componentInputs: any = this.handlerComponentInputs(inputs, componentName);
await this.report(componentName, methodName, undefined, inputs?.project?.access);
componentInputs.props = props;
Expand Down Expand Up @@ -138,7 +139,14 @@ export default class FcBaseComponent {

async build(inputs: IInputs): Promise<any> {
const { props, args } = this.handlerComponentInputs(inputs);
const parsedArgs: {[key: string]: any} = core.commandParse({ args }, {
boolean: ['help'],
alias: { help: 'h' } });

if (parsedArgs?.data?.help) {
core.help(BUILD_HELP_INFO);
return;
}
await this.componentMethodCaller(inputs, 'devsapp/fc-build', 'build', props, args);
tips.showNextTip(args, tips.showBuildNextTips);
}
Expand Down Expand Up @@ -215,22 +223,7 @@ export default class FcBaseComponent {
return;
}

const getConfig = (argsParse, inputsProps) => {
if (argsParse?.region) {
return {
region: argsParse.region,
serviceName: argsParse['service-name'],
functionName: argsParse['function-name'],
};
}
return {
region: inputsProps?.region,
serviceName: inputsProps?.service?.name,
functionName: inputsProps?.function?.name,
};
};

const { region, serviceName, functionName } = getConfig(comParse, props);
const { region, serviceName, functionName } = getFcNames(comParse, props);
this.logger.debug(`[logs] region: ${region}, serviceName: ${serviceName}, functionName: ${functionName}`);

let logsPayload: LogsProps;
Expand Down Expand Up @@ -260,11 +253,18 @@ export default class FcBaseComponent {
async metrics(inputs: IInputs): Promise<any> {
const { props, args } = this.handlerComponentInputs(inputs);

const payload: FcMetricsProps = {
region: props?.region,
serviceName: props?.service?.name,
functionName: props?.function?.name,
};
const comParse: any = core.commandParse({ args }, {
boolean: ['help'],
string: ['region', 'service-name', 'function-name'],
alias: { help: 'h' },
})?.data;

if (comParse?.help) {
core.help(METRICS_HELP_INFO);
return;
}

const payload: FcMetricsProps = getFcNames(comParse, props);

await this.componentMethodCaller(inputs, 'devsapp/fc-metrics', 'metrics', payload, args);
}
Expand Down
Loading

0 comments on commit 6f30f41

Please sign in to comment.