syntaxseed / terminalfaker

Terminal Faker - A client-side Linux-like cli terminal simulation written in Javascript. Originally forked from AVGP/terminal.js.
MIT License
51 stars 20 forks source link

Custom commands no longer listed by the 'help' command. #26

Closed syntaxseed closed 4 years ago

syntaxseed commented 4 years ago

Since the ES6 refactor PR #23 the 'help' command is no longer listing custom commands.

jxuan101 commented 4 years ago

Hi can I take a shot at this?

syntaxseed commented 4 years ago

@jxuan101 yes please! :)

jxuan101 commented 4 years ago

When I checked the output of all elements in the set returned from the function getAllMethodNames in src/main/components/utils.js called by the help command, I noticed that custom commands are not included in the output. Could you help me understand why this might be?

For some reason, the following modifications to the getAllMethodNames function fixes this issue,

export function getAllMethodNames(obj) {
  let methods = new Set();
  let clone = obj;
  if (Reflect.getPrototypeOf(clone)) {
    let keys = Reflect.ownKeys(clone);
    keys.forEach((k) => {
      methods.add(k);
    });
  }
  while (obj = Reflect.getPrototypeOf(obj)) {
    let keys = Reflect.ownKeys(obj);
    keys.forEach((k) => {
      methods.add(k);
    });
  }
  return [...methods];
}
jxuan101 commented 4 years ago

I would like a second opinion on this before I submit a pull request. Sorry for my inexperience :p.

syntaxseed commented 4 years ago

@jxuan101 this does indeed seem to fix the problems with the help. I'm not sure why myself.

Please go ahead and submit the PR. Thank you so much for your help!

jxuan101 commented 4 years ago

Welcome back! I cleaned up the code a bit but from what I understand, the getAllMethodNames function only listed the pseudo properties (get functions) in TerminalCommands.