nvm install rules 추가 (2편)

1 minute read

nvm install 명령어 rules 추가

전편 포스트는 여기서 확인하실 수 있습니다.

2. <version> 입력 시 <version>도 추천하도록 보완

이제 nvm install을 추천하게 되었지만, <version> 인자가 입력시에도 여전히 nvm install 만을 추천합니다.

따라서 <version> 입력 시

  • nvm install <version>와 같은 형식으로 추천하도록 합니다.

  • 만약 <version>에 적절한 인자가 입력되지 않는 경우에는 예외처리를 합니다.

def get_new_command(command):
	new_cmds = ["nvm"]
	nextcommand = []
	for e in command.script_parts[2:]:
		if e.replace('.', '', 2).isdigit():
		    nextcommand.append(e)
		else:
		    nextcommand = ["node"]
		    break	
	return [' '.join([new_command] + ["install"] + nextcommand) for new_command in new_cmds] 

Node.js의 버전들을 참고하면, 모두 int.int.int 형태를 띄고 있습니다. 따라서 <version> 입력시 .를 지우고 isdigit 함수를 사용하여 정수형이 맞는지를 확인합니다. 만약 오탈자가 입력된 경우, nvm install node 명령어를 추천하여 Node.js 최신 버전을 설치할 수 있도록 설계하였습니다.

nvm_install.py 추가 후 fuck 타이핑

nvm_install.py 추가 후 nvm install 명령어를 추천하는 것을 확인할 수 있습니다.

2

kuna@server:~$ nvm ins 12.18.0

Node Version Manager (v0.35.3)

Note: <version> refers to any version-like string nvm understands. This includes:
  - full or partial version numbers, starting with an optional "v" (0.10, v0.1.2, v1)
  - default (built-in) aliases: node, stable, unstable, iojs, system
  - custom aliases you define with `nvm alias foo`

...
(중략)
...

Note:
  to remove, delete, or uninstall nvm - just remove the `$NVM_DIR` folder (usually `~/.nvm`)

kuna@server:~$ fuck
nvm install 12.18.0 [enter/↑/↓/ctrl+c]

관련 커밋은 여기서 확인하실 수 있습니다.

    

Categories:

Updated: