Skip to content

Commit

Permalink
feat: support config client through feflow command (#125)
Browse files Browse the repository at this point in the history
  • Loading branch information
cpselvis committed Nov 14, 2019
1 parent ad90a9d commit b68df16
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 7 deletions.
2 changes: 1 addition & 1 deletion src/cli/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ export default function entry() {
return;
}

return feflow.init().then(() => {
return feflow.init(cmd).then(() => {
if (!args.h && !args.help) {
if (cmd) {
const c = commander.get(cmd);
Expand Down
18 changes: 12 additions & 6 deletions src/core/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ export default class Feflow {
public root: any;
public rootPkg: any;
public config: any;
public configPath: any;

constructor(args: any) {
args = args || {};
Expand All @@ -33,19 +34,24 @@ export default class Feflow {
this.args = args;
this.version = pkg.version;
this.config = parseYaml(configPath);
this.configPath = configPath;
this.commander = new Commander();
this.logger = logger({
debug: Boolean(args.debug),
silent: Boolean(args.silent)
});
}

async init() {
await this.initClient();
await this.checkUpdate();
await this.loadNative();
await loadPlugins(this);
await loadDevkits(this);
async init(cmd: string) {
if (cmd === 'config') {
await this.loadNative();
} else {
await this.initClient();
await this.checkUpdate();
await this.loadNative();
await loadPlugins(this);
await loadDevkits(this);
}
}

initClient() {
Expand Down
24 changes: 24 additions & 0 deletions src/core/native/config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import { safeDump } from '../../shared/yaml';

module.exports = (ctx: any) => {
const { args, config = {}, configPath } = ctx;
const [ action, key, value ] = args['_'];

ctx.commander.register('config', 'Config client', () => {
switch (action) {
case 'get':
console.log(ctx.config[key]);
case 'set':
config[key] = value;
safeDump(config, configPath);
case 'list':
let str = '';
for (let prop in config) {
str += prop + ' = ' + config[prop] + '\n';
}
console.log(str.replace(/\s+$/g, ''));
default:
return null;
}
});
};

0 comments on commit b68df16

Please sign in to comment.