-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
alqmc
authored and
alqmc
committed
Nov 9, 2022
1 parent
7fda76b
commit 5178486
Showing
6 changed files
with
71 additions
and
71 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,62 +1,62 @@ | ||
import prompts from 'prompts'; | ||
import { registriesPath } from '../../config/path'; | ||
import { getFileUser } from '../../utils/getUserList'; | ||
import { log } from '../../utils/log'; | ||
import { run } from '../../utils/shell'; | ||
import type { UserInfo } from '../../type/shell.type'; | ||
|
||
export interface UseCmd { | ||
local?: boolean; | ||
global?: boolean; | ||
system?: boolean; | ||
} | ||
|
||
export const useUse = async ([name]: string[], cmd: UseCmd) => { | ||
const userList = await getFileUser(registriesPath); | ||
|
||
if (!userList) return log.error(`no user exists`); | ||
|
||
let useUser: UserInfo | undefined = undefined; | ||
if (name) { | ||
useUser = userList.users.find((x) => x.alias === name); | ||
} else { | ||
const { user } = await prompts({ | ||
type: 'select', | ||
name: 'user', | ||
message: 'Pick a account', | ||
choices: userList.users.map((x) => { | ||
return { | ||
title: `${x.alias}${x.alias === x.name ? '' : `(${x.name})`} ${ | ||
x.email | ||
}`, | ||
value: x, | ||
}; | ||
}), | ||
}); | ||
if (!user) { | ||
log.error(`user cancel operation`); | ||
return; | ||
} | ||
useUser = user; | ||
} | ||
|
||
if (!useUser) return log.error(`${name} not found`); | ||
|
||
let env = 'local'; | ||
|
||
if (cmd.system) env = 'system'; | ||
|
||
if (cmd.global) env = 'global'; | ||
|
||
if (cmd.local) env = 'local'; | ||
|
||
await run(`git config --${env} user.name ${useUser.name}`); | ||
|
||
await run(`git config --${env} user.email ${useUser.email}`); | ||
|
||
log.success( | ||
`git user changed [${env}]:${useUser.alias}${ | ||
useUser.alias !== useUser.name ? `(${useUser.name})` : '' | ||
}` | ||
); | ||
}; | ||
import prompts from 'prompts'; | ||
import { registriesPath } from '../../config/path'; | ||
import { getFileUser } from '../../utils/getUserList'; | ||
import { log } from '../../utils/log'; | ||
import { run } from '../../utils/shell'; | ||
import type { UserInfo } from '../../type/shell.type'; | ||
|
||
export interface UseCmd { | ||
local?: boolean; | ||
global?: boolean; | ||
system?: boolean; | ||
} | ||
|
||
export const useUse = async (name: string, cmd: UseCmd) => { | ||
const userList = await getFileUser(registriesPath); | ||
|
||
if (!userList) return log.error(`no user exists`); | ||
|
||
let useUser: UserInfo | undefined = undefined; | ||
if (name) { | ||
useUser = userList.users.find((x) => x.alias === name); | ||
} else { | ||
const { user } = await prompts({ | ||
type: 'select', | ||
name: 'user', | ||
message: 'Pick a account', | ||
choices: userList.users.map((x) => { | ||
return { | ||
title: `${x.alias}${x.alias === x.name ? '' : `(${x.name})`} ${ | ||
x.email | ||
}`, | ||
value: x, | ||
}; | ||
}), | ||
}); | ||
if (!user) { | ||
log.error(`user cancel operation`); | ||
return; | ||
} | ||
useUser = user; | ||
} | ||
|
||
if (!useUser) return log.error(`${name} not found`); | ||
|
||
let env = 'local'; | ||
|
||
if (cmd.system) env = 'system'; | ||
|
||
if (cmd.global) env = 'global'; | ||
|
||
if (cmd.local) env = 'local'; | ||
|
||
await run(`git config --${env} user.name ${useUser.name}`); | ||
|
||
await run(`git config --${env} user.email ${useUser.email}`); | ||
|
||
log.success( | ||
`git user changed [${env}]:${useUser.alias}${ | ||
useUser.alias !== useUser.name ? `(${useUser.name})` : '' | ||
}` | ||
); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters