Skip to content
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

Closed
mdsb100 opened this issue Aug 13, 2018 · 12 comments · Fixed by #434
Closed

Add CLI functionality #146

mdsb100 opened this issue Aug 13, 2018 · 12 comments · Fixed by #434

Comments

@mdsb100
Copy link

mdsb100 commented Aug 13, 2018

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?

@jdalrymple
Copy link
Owner

That would be interesting! Adding CLI capabilities would be pretty cool. Could you provide an example of how you could do this with decorators?

@mdsb100
Copy link
Author

mdsb100 commented Aug 13, 2018

The idea like this:
In services/Users.js

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.

@mdsb100
Copy link
Author

mdsb100 commented Aug 13, 2018

I am coding.
See also https://github.com/mdsb100/node-gitlab, branch is 'cli'

@jdalrymple
Copy link
Owner

Cool!! Would this need to be changed if the library moved to typescript?

@jdalrymple
Copy link
Owner

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 ?

@mdsb100
Copy link
Author

mdsb100 commented Aug 14, 2018

Typescript can use decorators too.The CLI code still be es6 or ts as your want.
If there has a map, The CLI made with map easiler than decoaratora.

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:

@api('userID', {action: post, namespace:xxx})

@jdalrymple
Copy link
Owner

Here was the discussion about creating the map #104

@mdsb100
Copy link
Author

mdsb100 commented Aug 15, 2018

#147

@mdsb100 mdsb100 closed this as completed Aug 15, 2018
@jdalrymple jdalrymple modified the milestones: 4.0, 4.3 Sep 5, 2018
@jdalrymple jdalrymple reopened this Sep 5, 2018
@jdalrymple jdalrymple changed the title I want to refer to your opinion before I add CLI. Add CLI functionality Sep 5, 2018
@mdsb100
Copy link
Author

mdsb100 commented Sep 6, 2018

what is going on?

@jdalrymple
Copy link
Owner

I reopened this as to not forget about adding these changes :)

@jdalrymple jdalrymple removed this from the 4.3 milestone Nov 21, 2018
@jdalrymple jdalrymple added this to the 6.1.x milestone Jun 3, 2019
@jdalrymple jdalrymple modified the milestones: 6.x.x, 7.x.x, 8.x.x, 9.x.x Jul 2, 2019
@jdalrymple jdalrymple removed this from the 9.x.x milestone Jul 23, 2019
@jdalrymple
Copy link
Owner

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.

class Repository {
   showBlob(projectId, options){}
}

creates a commander option:

gitlab repository show-blob --projectId --other --optional --arguments --here

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.

jdalrymple added a commit that referenced this issue Aug 30, 2019
jdalrymple added a commit that referenced this issue Aug 30, 2019
jdalrymple added a commit that referenced this issue Aug 30, 2019
jdalrymple added a commit that referenced this issue Aug 30, 2019
jdalrymple pushed a commit that referenced this issue Sep 9, 2019
# [11.1.0](11.0.2...11.1.0) (2019-09-09)

### Features

* Adding support for CLI ([6f90f4c](6f90f4c)), closes [#146](#146)
@jdalrymple
Copy link
Owner

🎉 This issue has been resolved in version 11.1.0 🎉

The release is available on:

Your semantic-release bot 📦🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants