2023-07-03 12:16:58 +00:00
package cmd
import (
"codeberg.org/aryak/simplytranslate/utils"
"fmt"
2023-07-22 14:24:15 +00:00
"github.com/spf13/cobra"
2023-07-03 12:16:58 +00:00
)
var file string
var imgtxtCmd = & cobra . Command {
Use : "imgtxt" ,
Short : "Image -> Text." ,
Long : ` Convert given image (filename) to text using gosseract. ` ,
Run : func ( cmd * cobra . Command , args [ ] string ) {
2023-08-15 09:25:49 +00:00
text , err := utils . ImgTxt ( file )
if err != nil {
2023-08-15 14:33:00 +00:00
fmt . Println ( "Failed to convert image to text: " , err )
2023-08-15 09:25:49 +00:00
} else {
fmt . Println ( text )
}
2023-07-03 12:16:58 +00:00
} ,
}
func init ( ) {
rootCmd . AddCommand ( imgtxtCmd )
imgtxtCmd . Flags ( ) . StringVarP ( & file , "file" , "f" , "" , "The query SimplyTranslate will listen to. Defaults to 3000, and overrides the SIMPLYTRANSLATE_query environment variable." )
langlist = imgtxtCmd . Flag ( "file" ) . Value . String ( )
}