Example #1
0
func runCmd(cmd *command.Command, args []string) error {
	if len(args) == 0 {
		cmd.Usage()
		return os.ErrInvalid
	}
	if execWorkPath == "" {
		var err error
		execWorkPath, err = os.Getwd()
		if err != nil {
			fmt.Fprintf(os.Stderr, "liteide_stub exec: os.Getwd() false\n")
			command.SetExitStatus(3)
			command.Exit()
			return err
		}
	}
	fileName := args[0]

	filePath, err := exec.LookPath(fileName)
	if err != nil {
		filePath, err = exec.LookPath("./" + fileName)
	}
	if err != nil {
		fmt.Fprintf(os.Stderr, "liteide_stub exec: file %s not found\n", fileName)
		command.SetExitStatus(3)
		command.Exit()
	}

	fmt.Println("Starting Process", filePath, strings.Join(args[1:], " "), "...")

	command := exec.Command(filePath, args[1:]...)
	command.Dir = execWorkPath
	command.Stdin = os.Stdin
	command.Stdout = os.Stdout
	command.Stderr = os.Stderr

	err = command.Run()

	if err != nil {
		fmt.Println("\nEnd Process", err)
	} else {
		fmt.Println("\nEnd Process", "exit status 0")
	}

	exitWaitEnter()
	return nil
}
Example #2
0
func exitWaitEnter() {
	if !execWaitEnter {
		return
	}
	fmt.Println("\nPress enter key to continue")
	var s = [256]byte{}
	os.Stdin.Read(s[:])
	command.SetExitStatus(0)
	command.Exit()
}
Example #3
0
func runPresent(cmd *command.Command, args []string) error {
	if presentInput == "" || !isDoc(presentInput) {
		cmd.Usage()
		return os.ErrInvalid
	}

	if presentVerifyOnly {
		err := VerifyDoc(presentInput)
		if err != nil {
			fmt.Fprintf(os.Stderr, "present:%s", err)
			command.SetExitStatus(3)
			command.Exit()
		}
		return nil
	}
	w := os.Stdout
	if !presentStdout {
		if presentOutput == "" {
			presentOutput = presentInput + ".html"
		}
		ext := filepath.Ext(presentOutput)
		if ext != ".htm" && ext != ".html" {
			presentOutput += ".html"
		}
		var err error
		w, err = os.Create(presentOutput)
		if err != nil {
			fmt.Fprintf(os.Stderr, "present:%s", err)
			command.SetExitStatus(3)
			command.Exit()
		}
	}
	err := RenderDoc(w, presentInput)
	if err != nil {
		fmt.Fprintf(os.Stderr, "present:%s", err)
		command.SetExitStatus(3)
		command.Exit()
	}
	return nil
}
Example #4
0
func runAstView(cmd *command.Command, args []string) error {
	if len(args) == 0 {
		cmd.Usage()
		return os.ErrInvalid
	}
	if astViewStdin {
		view, err := NewFilePackageSource(args[0], os.Stdin, true)
		if err != nil {
			fmt.Fprintf(os.Stderr, "astview: %s", err)
			command.SetExitStatus(3)
			command.Exit()
		}
		view.PrintTree(os.Stdout)
	} else {
		err := PrintFilesTree(args, os.Stdout, true)
		if err != nil {
			fmt.Fprintf(os.Stderr, "astview:%s", err)
			command.SetExitStatus(3)
			command.Exit()
		}
	}
	return nil
}
Example #5
0
func runDocView(cmd *command.Command, args []string) error {
	if docViewFind == "" && docViewList == "" {
		cmd.Usage()
		return os.ErrInvalid
	}

	var template string
	var info *Info
	if len(docViewList) > 0 {
		pkgPath := filepath.Join(goroot, "src", docViewList)
		if docViewList == "pkg" {
			_, err := os.Stat(pkgPath)
			if err != nil {
				pkgPath = filepath.Join(goroot, "src")
			}
		}
		info = NewListInfo(pkgPath)
		if info != nil {
			if docViewList == "pkg" {
				var filterList []DirEntry
				for _, v := range info.Dirs.List {
					if v.Path == "cmd" {
						continue
					}
					if strings.HasPrefix(v.Path, "cmd/") {
						continue
					}
					if strings.Contains(v.Path, "/testdata") {
						continue
					}
					filterList = append(filterList, v)
				}
				info.Dirs.List = filterList
			} else if docViewList == "cmd" {
				var filterList []DirEntry
				for _, v := range info.Dirs.List {
					if strings.Contains(v.Path, "/") {
						continue
					}
					if strings.Contains(v.Path, "internal") {
						continue
					}
					filterList = append(filterList, v)
				}
				info.Dirs.List = filterList
			}
		}
		switch docViewMode {
		case "html":
			template = listHTML
		case "lite":
			template = listLite
		case "text":
			template = listText
		default:
			template = listText
		}
	} else if len(docViewFind) > 0 {
		dir := NewSourceDir(goroot)
		info = dir.FindInfo(docViewFind)
		switch docViewMode {
		case "html":
			template = findHTML
		case "lite":
			template = findLite
		case "text":
			template = findText
		default:
			template = findText
		}
	}
	if info == nil {
		fmt.Fprintf(os.Stderr, "<error>\n")
		command.SetExitStatus(3)
		command.Exit()
	}
	contents := info.GetPkgList(docViewMode, template)
	fmt.Fprintf(os.Stdout, "%s", contents)
	return nil
}