v symlink: extract to cmd/tools/vsymlink.v , use setx on windows
							parent
							
								
									b4eadb9030
								
							
						
					
					
						commit
						7585483c69
					
				|  | @ -0,0 +1,36 @@ | |||
| import os | ||||
| import v.pref | ||||
| 
 | ||||
| fn main(){ | ||||
| 	vexe := pref.vexe_path() | ||||
| 	$if windows { | ||||
| 		vdir := os.real_path(os.dir(vexe)) | ||||
| 		res := os.system('setx /M PATH "$vdir;%PATH%"') | ||||
| 		if res == 0 { | ||||
| 			println('v has been prepended to the path') | ||||
| 			exit(0) | ||||
| 		} | ||||
| 		exit(1) | ||||
| 	} | ||||
| 	//
 | ||||
| 	mut link_path := '/usr/local/bin/v' | ||||
| 	mut ret := os.exec('ln -sf $vexe $link_path') or { | ||||
| 		panic(err) | ||||
| 	} | ||||
| 	if ret.exit_code == 0 { | ||||
| 		println('Symlink "$link_path" has been created') | ||||
| 	} else if os.system("uname -o | grep -q \'[A/a]ndroid\'") == 0 { | ||||
| 		println('Failed to create symlink "$link_path". Trying again with Termux path for Android.') | ||||
| 		link_path = '/data/data/com.termux/files/usr/bin/v' | ||||
| 		ret = os.exec('ln -sf $vexe $link_path') or { | ||||
| 			panic(err) | ||||
| 		} | ||||
| 		if ret.exit_code == 0 { | ||||
| 			println('Symlink "$link_path" has been created') | ||||
| 		} else { | ||||
| 			println('Failed to create symlink "$link_path". Try again with sudo.') | ||||
| 		} | ||||
| 	} else { | ||||
| 		println('Failed to create symlink "$link_path". Try again with sudo.') | ||||
| 	} | ||||
| } | ||||
							
								
								
									
										58
									
								
								cmd/v/v.v
								
								
								
								
							
							
						
						
									
										58
									
								
								cmd/v/v.v
								
								
								
								
							|  | @ -12,12 +12,14 @@ import v.util | |||
| import v.builder | ||||
| 
 | ||||
| const ( | ||||
| 	simple_cmd                          = ['fmt', 'up' | ||||
| 	'self', 'test' | ||||
| 	'test-fmt', 'test-compiler', 'test-fixed', 'bin2v' | ||||
| 	'repl' | ||||
| 	'build-tools' | ||||
| 	'build-examples', 'build-vbinaries', 'setup-freetype' | ||||
| 	simple_cmd                          = [ | ||||
| 		'fmt', 'up', | ||||
| 		'self', 'symlink', 'bin2v', | ||||
| 		'test', 'test-fmt', 'test-compiler', 'test-fixed', | ||||
| 		'repl', | ||||
| 		'build-tools', 'build-examples', | ||||
| 		'build-vbinaries', | ||||
| 		'setup-freetype' | ||||
| 	] | ||||
| 	list_of_flags_that_allow_duplicates = ['cc', 'd', 'define', 'cf', 'cflags'] | ||||
| ) | ||||
|  | @ -39,10 +41,10 @@ fn main_v() { | |||
| 	} | ||||
| 	args_and_flags := util.join_env_vflags_and_os_args()[1..] | ||||
| 	prefs, command := pref.parse_args(args_and_flags) | ||||
| 	//if prefs.is_verbose {
 | ||||
| 		//println('command = "$command"')
 | ||||
| 		//println(util.full_v_version(prefs.is_verbose))
 | ||||
| 	//}
 | ||||
| 	// if prefs.is_verbose {
 | ||||
| 	// println('command = "$command"')
 | ||||
| 	// println(util.full_v_version(prefs.is_verbose))
 | ||||
| 	// }
 | ||||
| 	if args.len > 0 && (args[0] in ['version', '-V', '-version', '--version'] || (args[0] == | ||||
| 		'-v' && args.len == 1)) { | ||||
| 		// `-v` flag is for setting verbosity, but without any args it prints the version, like Clang
 | ||||
|  | @ -86,16 +88,11 @@ fn main_v() { | |||
| 			println(util.full_v_version(prefs.is_verbose)) | ||||
| 			return | ||||
| 		} | ||||
| 		'symlink' { | ||||
| 			create_symlink() | ||||
| 			return | ||||
| 		} | ||||
| 		'doc' { | ||||
| 			mut mod := '' | ||||
| 			if args.len == 1 { | ||||
| 				println('v doc [module]') | ||||
| 			} | ||||
| 			else if args.len > 1 { | ||||
| 			} else if args.len > 1 { | ||||
| 				mod = args[1] | ||||
| 			} | ||||
| 			table := table.new_table() | ||||
|  | @ -124,32 +121,3 @@ fn invoke_help_and_exit(remaining []string) { | |||
| 	println('For usage information, use `v help`.') | ||||
| 	exit(1) | ||||
| } | ||||
| 
 | ||||
| fn create_symlink() { | ||||
| 	$if windows { | ||||
| 		return | ||||
| 	} | ||||
| 	vexe := pref.vexe_path() | ||||
| 	mut link_path := '/usr/local/bin/v' | ||||
| 	mut ret := os.exec('ln -sf $vexe $link_path') or { | ||||
| 		panic(err) | ||||
| 	} | ||||
| 	if ret.exit_code == 0 { | ||||
| 		println('Symlink "$link_path" has been created') | ||||
| 	} else if os.system("uname -o | grep -q \'[A/a]ndroid\'") == 0 { | ||||
| 		println('Failed to create symlink "$link_path". Trying again with Termux path for Android.') | ||||
| 		link_path = '/data/data/com.termux/files/usr/bin/v' | ||||
| 		ret = os.exec('ln -sf $vexe $link_path') or { | ||||
| 			panic(err) | ||||
| 		} | ||||
| 		if ret.exit_code == 0 { | ||||
| 			println('Symlink "$link_path" has been created') | ||||
| 		} else { | ||||
| 			println('Failed to create symlink "$link_path". Try again with sudo.') | ||||
| 		} | ||||
| 	} else { | ||||
| 		println('Failed to create symlink "$link_path". Try again with sudo.') | ||||
| 	} | ||||
| } | ||||
| 
 | ||||
| 
 | ||||
|  |  | |||
		Loading…
	
		Reference in New Issue