cmd

package
v0.0.0-...-9b865c2 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Feb 10, 2025 License: MIT Imports: 6 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	Main = gcmd.Command{
		Name:  "main",
		Usage: "main",
		Brief: "Convert various file formats to markdown.",
		Func: func(ctx context.Context, parser *gcmd.Parser) (err error) {
			var (
				fileSource string
				outputPath string
			)
			allArgList := parser.GetArgAll()
			fileSourceOpt := parser.GetOpt("f")
			outputPathOpt := parser.GetOpt("o")
			if fileSourceOpt.IsNil() || fileSourceOpt.String() == "" {
				if len(allArgList) >= 2 {
					fileSource = allArgList[1]
				} else {
					err = errors.New("Please input the path of the file to be converted with the -f parameter.")
					return
				}
			} else {
				fileSource = fileSourceOpt.String()
			}

			if outputPathOpt.IsNil() {
				if len(allArgList) >= 3 {
					outputPath = allArgList[2]
				} else {
					outputPath, err = os.Getwd()
					if err != nil {
						return err
					}
					outputPath = outputPath + "/markitdown_output.md"
				}
			} else {
				outputPath = outputPathOpt.String()
			}

			result, err := markitdown.Convert(fileSource, outputPath)
			title := result.Title
			content := result.Content

			if err == nil {
				fmt.Printf("Title: %s\nContent: %s\n", title, content)
			}

			return err
		},
	}
)

Functions

This section is empty.

Types

This section is empty.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL