func readDocOpts()

in ops.go [160:203]


func readDocOpts() (string, string) {
	if os.Getenv("OPS_NO_DOCOPTS") != "" {
		if exists(".", DOCOPTS_TXT) {
			fmt.Printf("Warning: ignoring %s - you have to provide all the options.\n", DOCOPTS_TXT)
		}
		if exists(".", DOCOPTS_MD) {
			fmt.Printf("Warning: ignoring %s - you have to provide all the options.\n", DOCOPTS_MD)
		}
		return "", ""
	}
	if exists(".", DOCOPTS_MD) {
		text := readfile(DOCOPTS_MD)

		// parse embedded variables
		restrictions := &parse.Restrictions{false, false, true}
		result, err := (&parse.Parser{Name: "string", Env: os.Environ(), Restrict: restrictions, Mode: parse.AllErrors}).Parse(text)
		if err != nil {
			return "", err.Error()
		}
		// convert to markdown
		help := tools.MarkdownToText(result)
		// extract the embedded usage
		opts := tools.ExtractUsage(result)

		// warn if there is a docopts.txt
		if exists(".", DOCOPTS_TXT) {
			help = fmt.Sprintf("%s\nWarning: both %s and %s are present, %s ignored.",
				help, DOCOPTS_TXT, DOCOPTS_MD, DOCOPTS_TXT)
		}
		return opts, help
	}

	if exists(".", DOCOPTS_TXT) {
		text := readfile(DOCOPTS_TXT)
		restrictions := &parse.Restrictions{false, false, true}
		help, err := (&parse.Parser{Name: "string", Env: os.Environ(), Restrict: restrictions, Mode: parse.AllErrors}).Parse(text)
		if err != nil {
			help = err.Error()
		}
		return help, help
	}

	return "", ""
}