File tree Expand file tree Collapse file tree 2 files changed +27
-7
lines changed Expand file tree Collapse file tree 2 files changed +27
-7
lines changed Original file line number Diff line number Diff line change @@ -2,6 +2,7 @@ import { clone } from '../git'
2
2
import { parseCliOptionsToGitArgs } from '../args'
3
3
import type { PluginApi } from '../types'
4
4
import { readConfig } from '../config'
5
+ import { analyzeUrl } from '../url'
5
6
6
7
export const cloneCommand : PluginApi = {
7
8
extend ( api ) {
@@ -13,17 +14,28 @@ export const cloneCommand: PluginApi = {
13
14
type : [ Boolean ] ,
14
15
} )
15
16
. ignoreOptionDefaultValue ( )
17
+ . example ( 'ghq clone ghq (requires `.gitconfig` has `github.user` or `user.name`)' )
16
18
. example ( 'ghq clone 2nthony/ghq' )
17
19
. example ( 'ghq clone github.com/2nthony/ghq' )
18
20
. example ( 'ghq clone https://github.com/2nthony/ghq' )
19
21
. example ( 'ghq get 2nthony/ghq' )
20
22
. allowUnknownOptions ( )
21
- . action ( async ( repo , options ) => {
23
+ . action ( async ( repo : string , options ) => {
22
24
if ( ! repo ) {
23
25
api . cli . outputHelp ( )
24
26
return
25
27
}
26
28
29
+ // ghq clone [repo]
30
+ // means clone my repos?
31
+ if ( ! repo . includes ( '/' ) ) {
32
+ const { user } = analyzeUrl ( repo )
33
+ if ( ! user ) {
34
+ api . cli . outputHelp ( )
35
+ return
36
+ }
37
+ }
38
+
27
39
const config = await readConfig ( )
28
40
const args = parseCliOptionsToGitArgs ( { ...config , ...options } )
29
41
Original file line number Diff line number Diff line change @@ -39,11 +39,19 @@ export async function init(repoUrl: string, ...args: string[]) {
39
39
}
40
40
41
41
function getUsername ( ) {
42
- try {
43
- const stdout = execSync ( 'git config --get user.name' )
44
- return stdout . toString ( ) . trim ( )
45
- }
46
- catch {
47
- return ''
42
+ let username = ''
43
+ function get ( keypath : string ) {
44
+ try {
45
+ return execSync ( `git config --get ${ keypath } ` ) . toString ( ) . trim ( )
46
+ }
47
+ catch {
48
+ return ''
49
+ }
48
50
}
51
+
52
+ username = get ( 'github.user' )
53
+ if ( ! username )
54
+ username = get ( 'user.name' )
55
+
56
+ return username
49
57
}
You can’t perform that action at this time.
0 commit comments