Skip to content

Better CLI - #2372

Merged
joshaber merged 48 commits into
desktop:masterfrom
j-f1:better-cli
Oct 13, 2017
Merged

joshaber merged 48 commits into
desktop:masterfrom
j-f1:better-cli

Conversation

@j-f1

@j-f1 j-f1 commented Jul 31, 2017 •

Copy link
Copy Markdown
Contributor

✨ ✨ ✨

$ github help
Commands:
  clone <url|slug>  Clone a repository                       
  help [command]    HALP!!1                                  
  open <path>       Open a git repository in GitHub Desktop  

Run github help <command> for details about each command

$ github help clone
github clone <url|slug>

Clone a repository

Options:
  --branch, -b  The branch to switch to after cloning  [string]  

Arguments:
  url|slug  (required)  The URL to clone, or the GitHub repo slug to clone  [string]  

$ github help open
github open <path>
github <path>

Open a git repository in GitHub Desktop

Arguments:
  path    The path to the repository to open  [string]

$ github # -> open Desktop
$ github path/to/repo # -> equivalent to `github open path/to/repo`

Run it locally (npm -s run cli -- [...args]) to get the full experience.

j-f1 added 3 commits July 31, 2017 15:42
If the `url` passed to the openDesktop function contained shell metacharacters, they would not get escaped, leading to arbitrary code execution.
@shiftkey shiftkey added the ready-for-review Pull Requests that are ready to be reviewed by the maintainers label Jul 31, 2017
Comment thread app/src/cli/commands/clone.ts Outdated
import * as QueryString from 'querystring'
import { URL } from 'url'

import * as yargs from 'yargs'

This comment was marked as spam.

This comment was marked as spam.

This comment was marked as spam.

This comment was marked as spam.

This comment was marked as spam.

@shiftkey shiftkey removed the ready-for-review Pull Requests that are ready to be reviewed by the maintainers label Aug 1, 2017
@j-f1

j-f1 commented Aug 1, 2017

Copy link
Copy Markdown
Contributor Author

I forgot to mention that this PR depends on this PR, which should be published to npm in the near future.

@shiftkey

shiftkey commented Aug 2, 2017

Copy link
Copy Markdown
Member

I'd like to look at whether we can make webpack happy with yargs - these warnings seem important:

WARNING in ./app/~/yargs/index.js
11:39-46 Critical dependency: require function is used in a way in which dependencies cannot be statically extracted

WARNING in ./app/~/yargs/yargs.js
341:33-40 Critical dependency: require function is used in a way in which dependencies cannot be statically extracted

WARNING in ./app/~/yargs/yargs.js
497:71-78 Critical dependency: require function is used in a way in which dependencies cannot be statically extracted

WARNING in ./app/~/yargs/lib/apply-extends.js
27:24-55 Critical dependency: the request of a dependency is an expression

WARNING in ./app/~/yargs/lib/apply-extends.js
42:82-105 Critical dependency: the request of a dependency is an expression

WARNING in ./app/~/yargs-parser/index.js
449:21-48 Critical dependency: the request of a dependency is an expression

@shiftkey shiftkey added the ready-for-review Pull Requests that are ready to be reviewed by the maintainers label Aug 2, 2017
@shiftkey

shiftkey commented Aug 2, 2017

Copy link
Copy Markdown
Member

As this currently stands it adds a significant amount JS to the cli.js bundle:

cli.js  979 bytes       0  [emitted]  cli
...
cli.js  178 kB       0  [emitted]  cli

main.js isn't much larger, for reference:

main.js  188 kB       0  [emitted]  main

@j-f1

j-f1 commented Aug 2, 2017

Copy link
Copy Markdown
Contributor Author

Do you know if it would be possible to dynamically generate the cli/main.ts file before running webpack on it? If I could do that, it would be fairly simple to find all of the .ts files in cli/commands and list them in the main file:

import * as yargs from 'yargs'
import * as clone from './commands/clone'
import * as open from './commands/open'
// import * as ${fileName} from './commands/${fileName}'

yargs
  .command(clone)
  .command(open)
// .command(${fileName})
  .help().argv

@j-f1

j-f1 commented Aug 3, 2017

Copy link
Copy Markdown
Contributor Author

Updated and shrinkified:

Hash: 881f45a20f94ca89b8b9
Version: webpack 2.7.0
Time: 14724ms
     Asset     Size  Chunks             Chunk Names
    cli.js  29.4 kB       0  [emitted]  cli
cli.js.map  80.2 kB       0  [emitted]  cli
chunk    {0} cli.js, cli.js.map (cli) 56.3 kB [entry] [rendered]
    [0] ./app/src/cli/util.ts 1.86 kB {0} [built]
    [1] ./app/~/chalk/index.js 6 kB {0} [built]
    [2] ./app/src/cli/load-commands.ts 373 bytes {0} [built]
    [5] external "path" 42 bytes {0} [not cacheable]
    [6] ./app/~/mri/lib/index.js 3.37 kB {0} [built]
    [7] ./app/~/ansi-regex/index.js 253 bytes {0} [built]
    [8] ./app/~/ansi-styles/index.js 3.35 kB {0} [built]

    [9] ./app/~/chalk/templates.js 3.92 kB {0} [built]
   [13] ./app/~/escape-string-regexp/index.js 226 bytes {0} [built]
   [15] ./app/~/strip-ansi/index.js 150 bytes {0} [built]
   [16] ./app/~/supports-color/index.js 2.27 kB {0} [built]
   [17] ./app/src/cli/command-list.json 48 bytes {0} [built]
   [18] ./app/src/cli/commands ^\.\/.*\.ts$ 203 bytes {0} [built]
   [22] ./app/src/cli/main.ts 2.8 kB {0} [built]
   [23] (webpack)/buildin/module.js 517 bytes {0} [built]
     + 13 hidden modules

@j-f1

j-f1 commented Aug 7, 2017

Copy link
Copy Markdown
Contributor Author

⏩

@desktop desktop deleted a comment Aug 7, 2017
@shiftkey shiftkey mentioned this pull request Aug 9, 2017
@joshaber joshaber self-assigned this Aug 9, 2017

@joshaber joshaber left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This definitely looks much nicer/friendlier than it did before 😍

⛱

Comment thread app/src/cli/commands/clone.ts Outdated
import { ICommandModule, mriArgv } from '../load-commands'

interface ICloneArgs extends mriArgv {
pr?: number

This comment was marked as spam.

This comment was marked as spam.

Comment thread app/src/cli/commands/open.ts Outdated
args: [
{
name: 'path',
description: 'The path to the repository to open. Defaults to `.`',

This comment was marked as spam.

This comment was marked as spam.

This comment was marked as spam.

This comment was marked as spam.

Comment thread app/src/cli/main.ts Outdated

const command = __DARWIN__ ? 'open' : 'start'
ChildProcess.exec(`${command} ${url}`, { env })
/// <reference path="../../typings/mri.d.ts"/>

This comment was marked as spam.

This comment was marked as spam.

Comment thread app/src/cli/main.ts
args = [name]
runCommand('help')
}
})(commandArg)

This comment was marked as spam.

This comment was marked as spam.

Comment thread package.json Outdated
"@types/ua-parser-js": "^0.7.30",
"@types/uuid": "^2.0.29",
"@types/winston": "^2.2.0",
"@types/yargs": "^8.0.2",

This comment was marked as spam.

This comment was marked as spam.

Comment thread app/src/cli/commands/clone.ts Outdated
cloneUrl = `https://github.com/${cloneUrl}`
}
if (pr) {
branch = 'pr/' + pr

This comment was marked as spam.

This comment was marked as spam.

This comment was marked as spam.

Comment thread app/src/cli/commands/clone.ts Outdated
pr: {
type: 'number',
aliases: ['p'],
description: 'The PR branch to switch to after cloning',

This comment was marked as spam.

This comment was marked as spam.

Comment thread app/src/cli/commands/clone.ts Outdated
type: 'string',
},
{
name: 'path',

This comment was marked as spam.

This comment was marked as spam.

This comment was marked as spam.

This comment was marked as spam.

This comment was marked as spam.

This comment was marked as spam.

Comment thread app/src/cli/load-commands.ts Outdated
export { mriArgv }

export interface IOption {
type: TypeName

This comment was marked as spam.

This comment was marked as spam.

Comment thread app/src/cli/load-commands.ts Outdated
unknownOptionHandler?: (flag: string) => void
}

const loadModule: (name: string) => ICommandModule = name =>

This comment was marked as spam.

This comment was marked as spam.

@shiftkey

shiftkey commented Sep 13, 2017 •

Copy link
Copy Markdown
Member

Ugh, found this which I thought was previously working:

Also npm run build:dev && npm run cli generates this error (because those files aren't loaded through webpack, and it's trying to spawn github because that's the default without any args):

> @ cli C:\Users\shiftkey\src\desktop
> ts-node --require ./app/src/cli/dev-commands-global.js app/src/cli/main.ts

ERR! __DARWIN__ is not defined
ReferenceError: __DARWIN__ is not defined
    at Object.openDesktop (C:\Users\shiftkey\src\desktop\app\src\cli\open-desktop.ts:9:7)
    at Object.handler (C:\Users\shiftkey\src\desktop\app\src\cli\commands\open.ts:30:5)
    at runCommand (C:\Users\shiftkey\src\desktop\app\src\cli\main.ts:101:11)
    at attemptRun (C:\Users\shiftkey\src\desktop\app\src\cli\main.ts:25:9)
    at Object.<anonymous> (C:\Users\shiftkey\src\desktop\app\src\cli\main.ts:37:3)
    at Module._compile (module.js:571:32)
    at Module.m._compile (C:\Users\shiftkey\src\desktop\node_modules\ts-node\src       \index.ts:392:23)
    at Module._extensions..js (module.js:580:10)
    at Object.require.extensions.(anonymous function) [as .ts] (C:\Users\shiftke       y\src\desktop\node_modules\ts-node\src\index.ts:395:12)
    at Module.load (module.js:488:32)
Commands:
  clone <url|slug>  Clone a repository
  help [command]    Show the help page for a command
  open <path>       Open a git repository in GitHub Desktop

Run github help <command> for details about each command

@shiftkey
shiftkey dismissed their stale review September 13, 2017 02:21

Upstream changes have been merged in, gotta start over

@j-f1

j-f1 commented Sep 13, 2017

Copy link
Copy Markdown
Contributor Author

@shiftkey That error was because I forgot to prepend the protocol to the URL in openDesktop. This way, the protocol name can be changed in the future in only one place.

@j-f1

j-f1 commented Sep 19, 2017 •

Copy link
Copy Markdown
Contributor Author

From #2775:

  1. github . from a sub-directory in my git clone opens a prompt to add a new local repository instead of detecting the local repository I've already added.
  2. github (without the dot) should have the same behavior as github . IMO

Note: git rev-parse --show-toplevel returns the absolute path to the repository root.

@shiftkey

Copy link
Copy Markdown
Member
  • 👍 on 1
  • 👎 on 2, but that's more a personal feeling than anything serious. @haacked feels?

@j-f1

j-f1 commented Sep 19, 2017

Copy link
Copy Markdown
Contributor Author

👎 on 2

Why? It seems like a good default.

@shiftkey

Copy link
Copy Markdown
Member

Why? It seems like a good default.

Two things I think of which would annoy me:

  • in a folder that's not tracked => github would prompt me to add it
  • in a folder that's a Git repository and already tracked => github would switch to this repository

I'd rather leave the defaults as "launch the app to whatever you had previously", the two extra characters are a minor inconvenience and eliminate opportunities to confuse users.

@haacked

haacked commented Sep 19, 2017

Copy link
Copy Markdown
Contributor

Ah, that's a good point. I sometimes will be doing random stuff in my shell and want to launch GitHub real quick. If I'm in c:\Windows\System32 I certainly don't want to be prompted to add that directory as a Git repo.

@shiftkey

Copy link
Copy Markdown
Member

I've opened #2832 to track the first item as that's a bug which also affects drag-and-dropping subfolders of repositories into the app, and can be fixed separate to this.

I'm going to leave the second item aside unless others have strong feelings on this and can convince me otherwise.

@blakek

blakek commented Sep 27, 2017

Copy link
Copy Markdown

Not sure if this is the issue to ask on, but on #2775 it was mentioned that running just github may default to opening the current directory in GitHub Desktop—the same behavior as github ..

Is that still a possibility? If so, is there any documentation or adjustments I could help with? Thanks!

@shiftkey

Copy link
Copy Markdown
Member

@blakek I'm not a fan of making github (without any arguments) behave the same as github . - see this comment from earlier for some examples where it could be confusing #2372 (comment)

@shiftkey

Copy link
Copy Markdown
Member

Alright, I think this is ready to go. As I've been involved with this I'm going to need someone else to 👍 it and hit the green button. Happy to answer any other questions that the reviewer might have in the meantime.

@shiftkey shiftkey removed their assignment Sep 27, 2017
@j-f1

j-f1 commented Oct 3, 2017

Copy link
Copy Markdown
Contributor Author

🌈

@joshaber joshaber self-assigned this Oct 12, 2017

@joshaber joshaber left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🤘

@joshaber
joshaber merged commit ffec232 into desktop:master Oct 13, 2017
@j-f1
j-f1 deleted the better-cli branch October 13, 2017 19:17
@j-f1

j-f1 commented Oct 13, 2017

Copy link
Copy Markdown
Contributor Author

🎉 🎉 🎉

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ready-for-review Pull Requests that are ready to be reviewed by the maintainers

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants