2023-07-03 17:46:58 +05:30
package cmd
import (
2023-08-27 17:22:32 +05:30
"codeberg.org/aryak/mozhi/utils"
2023-07-03 17:46:58 +05:30
"fmt"
2023-07-22 19:54:15 +05:30
"github.com/spf13/cobra"
2023-07-03 17:46:58 +05:30
)
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 14:55:49 +05:30
text , err := utils . ImgTxt ( file )
if err != nil {
2023-08-15 20:03:00 +05:30
fmt . Println ( "Failed to convert image to text: " , err )
2023-08-15 14:55:49 +05:30
} else {
fmt . Println ( text )
}
2023-07-03 17:46:58 +05:30
} ,
}
func init ( ) {
rootCmd . AddCommand ( imgtxtCmd )
2023-08-27 17:22:32 +05:30
imgtxtCmd . Flags ( ) . StringVarP ( & file , "file" , "f" , "" , "The query Mozhi will listen to. Defaults to 3000, and overrides the MOZHI_query environment variable." )
2023-07-03 17:46:58 +05:30
langlist = imgtxtCmd . Flag ( "file" ) . Value . String ( )
}