mirror of
				https://github.com/Dadido3/go-typst.git
				synced 2025-11-03 20:59:35 +00:00 
			
		
		
		
	Add VersionString method
This commit is contained in:
		
							parent
							
								
									f42f1cb385
								
							
						
					
					
						commit
						88837c7ba0
					
				
							
								
								
									
										28
									
								
								cli.go
									
									
									
									
									
								
							
							
						
						
									
										28
									
								
								cli.go
									
									
									
									
									
								
							@ -18,7 +18,33 @@ type CLI struct {
 | 
			
		||||
	ExecutablePath string // The typst executable path can be overridden here. Otherwise the default path will be used.
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// TODO: Method for querying typst version
 | 
			
		||||
// TODO: Add method for querying the typst version resulting in a semver object
 | 
			
		||||
 | 
			
		||||
// VersionString returns the version string as returned by typst.
 | 
			
		||||
func (c CLI) VersionString() (string, error) {
 | 
			
		||||
	// Get path of executable.
 | 
			
		||||
	execPath := ExecutablePath
 | 
			
		||||
	if c.ExecutablePath != "" {
 | 
			
		||||
		execPath = c.ExecutablePath
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	cmd := exec.Command(execPath, "--version")
 | 
			
		||||
 | 
			
		||||
	var output, errBuffer bytes.Buffer
 | 
			
		||||
	cmd.Stdout = &output
 | 
			
		||||
	cmd.Stderr = &errBuffer
 | 
			
		||||
 | 
			
		||||
	if err := cmd.Run(); err != nil {
 | 
			
		||||
		switch err := err.(type) {
 | 
			
		||||
		case *exec.ExitError:
 | 
			
		||||
			return "", ParseStderr(errBuffer.String(), err)
 | 
			
		||||
		default:
 | 
			
		||||
			return "", err
 | 
			
		||||
		}
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	return output.String(), nil
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// Render takes a typst document from input, and renders it into the output writer.
 | 
			
		||||
// The options parameter is optional.
 | 
			
		||||
 | 
			
		||||
@ -15,6 +15,15 @@ import (
 | 
			
		||||
	"github.com/Dadido3/go-typst"
 | 
			
		||||
)
 | 
			
		||||
 | 
			
		||||
func TestCLI_VersionString(t *testing.T) {
 | 
			
		||||
	cli := typst.CLI{}
 | 
			
		||||
 | 
			
		||||
	_, err := cli.VersionString()
 | 
			
		||||
	if err != nil {
 | 
			
		||||
		t.Fatalf("Failed to get typst version: %v.", err)
 | 
			
		||||
	}
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// Test basic render functionality.
 | 
			
		||||
func TestCLI_Render(t *testing.T) {
 | 
			
		||||
	const inches = 1
 | 
			
		||||
 | 
			
		||||
		Loading…
	
		Reference in New Issue
	
	Block a user