//newSearchCmd returns cobra.Command instance for show sub-command
newSearchCmd returns cobra.Command instance for show sub-command
// newSearchCmd returns cobra . Command instance for show sub - command
func newSearchCmd(ui *rwi.RWI) *cobra.Command {
	searchCmd := &cobra.Command{
		Use:   "search [flags]",
		Short: "Search for books data",
		Long:  "Search for books data",
		RunE: func(cmd *cobra.Command, args []string) error {
			rawFlag, err := cmd.Flags().GetBool("raw")
			if err != nil {
				return errs.New("--raw", errs.WithCause(err))
			}
			ctx := signal.Context(context.Background(), os.Interrupt)
			var lastError error
			if len(asin) > 0 {
				p, err := getPaapiParams()
				if err != nil {
					return debugPrint(ui, err)
				}
				r, err := searchPAAPI(ctx, asin, p, rawFlag)
				if err == nil {
					return debugPrint(ui, ui.WriteFrom(r))
				}
				if !checkError(err) {
					return debugPrint(ui, err)
				}
				lastError = err
			}
			if len(isbn) > 0 {
				r, err := searchOpenBD(ctx, isbn, rawFlag)
				if err == nil {
					return debugPrint(ui, ui.WriteFrom(r))
				}
				if !checkError(err) {
					return debugPrint(ui, err)
				}
				lastError = err
			}
			if len(card) > 0 {
				r, err := searchAozoraAPI(ctx, card, rawFlag)
				if err == nil {
					return debugPrint(ui, ui.WriteFrom(r))
				}
				if !checkError(err) {
					return debugPrint(ui, err)
				}
				lastError = err
			}
			return debugPrint(ui, lastError)
		},
	}
	searchCmd.Flags().BoolP("raw", "", false, "Output raw data from API")
	return searchCmd
}
func newSearchCmd ( ui * rwi . RWI ) * cobra . Command { searchCmd := & cobra . Command { Use : " " , Short : " " , Long : " " , RunE : func ( cmd * cobra . Command , args [ ] string ) error { rawFlag , err := cmd . Flags ( ) . GetBool ( " " ) if err != nil { return errs . New ( " " , errs . WithCause ( err ) ) } ctx := signal . Context ( context . Background ( ) , os . Interrupt ) var lastError error if len ( asin ) > 0 { p , err := getPaapiParams ( ) if err != nil { return debugPrint ( ui , err ) } r , err := searchPAAPI ( ctx , asin , p , rawFlag ) if err == nil { return debugPrint ( ui , ui . WriteFrom ( r ) ) } if ! checkError ( err ) { return debugPrint ( ui , err ) } lastError = err } if len ( isbn ) > 0 { r , err := searchOpenBD ( ctx , isbn , rawFlag ) if err == nil { return debugPrint ( ui , ui . WriteFrom ( r ) ) } if ! checkError ( err ) { return debugPrint ( ui , err ) } lastError = err } if len ( card ) > 0 { r , err := searchAozoraAPI ( ctx , card , rawFlag ) if err == nil { return debugPrint ( ui , ui . WriteFrom ( r ) ) } if ! checkError ( err ) { return debugPrint ( ui , err ) } lastError = err } return debugPrint ( ui , lastError ) } , } searchCmd . Flags ( ) . BoolP ( " " , " " , false , " " ) return searchCmd }
newSearchCmd returns cobra.Command instance for show sub-command
newSearchCmd returns cobra . Command instance for show sub - command
//Raw flag (PA-API) //Create context //Search by ASIN code //Search by ISBN code //by openBD //by Aozora-API //options