-
-
Notifications
You must be signed in to change notification settings - Fork 299
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add CLI functionality #146
Comments
That would be interesting! Adding CLI capabilities would be pretty cool. Could you provide an example of how you could do this with decorators? |
The idea like this: import { api, cls } from '../cli/worker';
@cls
class Users extends BaseService {
@api({ alias: 'whoami' })
current() {
return RequestHelper.get(this, 'user');
}
} In my work space, use commander.js export function cls(target) {
if (NAMESPACE) {
return;
}
const clsName = kebabCase(target.name);
const commander = createCommand(program, clsName, `use gitlab-${clsName}`);
}
export function api(...args) {
// copy
const argsArr = args.slice();
let options;
if (!isString(argsArr[argsArr.length - 1])) {
// remove options
const { 0: last } = argsArr.splice(-1, 1);
options = last;
}
return (target, fnName, descriptor) => {
const clsName = target.constructor.name;
if (NAMESPACE === clsName) {
const commander = createCommand(program, fnName, options.desc, argsArr);
commander.allowUnknownOption(true);
createAlias(commander, options);
createAction(commander, clsName, fnName);
}
return descriptor;
};
} One or two days later, I will give a merge request. The first version may not be so good. You can give me some good advice. |
I am coding. |
Cool!! Would this need to be changed if the library moved to typescript? |
Also, we are looking into updating the library to using a map generated from the gitlab docs instead of manually writing each of services. If we did do this, can decorators be dynamically added ? |
Typescript can use decorators too.The CLI code still be es6 or ts as your want. About map, I have a idea. Write a script to requeat official document and auto create map.If we do not do this, I think use decorators describe api is a good way. example:
|
Here was the discussion about creating the map #104 |
what is going on? |
I reopened this as to not forget about adding these changes :) |
Updates! So i took another shot at this, and my implementation realllllly cut down the amount of files needed to support this functionality. Basically, the inital idea was to generate the commander program at runtime based on the function headers of the API's. I did this by looping through each service, reading the function header and dynamically creating the commander options. ie.
creates a commander option:
where everything after projectId is seen as options arguments. This implementation would be amazing ifffffffff the compiled code didnt change the function headers 🙃 . Currently im trying to work around this by running a second build step before compilation that tried to run the ts code as if it were a es6 module (to avoid compiling down to es5 which changes the method headers). Im still running into problems with this however, but im sure ill figure something out soon. |
# [11.1.0](11.0.2...11.1.0) (2019-09-09) ### Features * Adding support for CLI ([6f90f4c](6f90f4c)), closes [#146](#146)
🎉 This issue has been resolved in version 11.1.0 🎉 The release is available on: Your semantic-release bot 📦🚀 |
Hi, I am maintaining cli-gitlab. I want to refactor to upgrade [email protected].
I have an idea to use the decorators to provide CLI, then I don't have to maintain a CLI map. So I plan to fork this project and directly plus a decorators into the service.
If you can accept my pull request, which is to provide CLI in this project, then I don't need to publish a npm library of [email protected].
Can you accept my idea?
The text was updated successfully, but these errors were encountered: