-
-
Notifications
You must be signed in to change notification settings - Fork 53
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1268 from rsteube/add-ebook-convert
added ebook-convert
- Loading branch information
Showing
2 changed files
with
65 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
package cmd | ||
|
||
import ( | ||
"strings" | ||
|
||
"github.com/rsteube/carapace" | ||
"github.com/rsteube/carapace/pkg/style" | ||
"github.com/spf13/cobra" | ||
) | ||
|
||
var rootCmd = &cobra.Command{ | ||
Use: "ebook-convert", | ||
Short: "Convert an e-book from one format to another", | ||
Long: "https://manual.calibre-ebook.com/de/generated/de/ebook-convert.html", | ||
Run: func(cmd *cobra.Command, args []string) {}, | ||
} | ||
|
||
func Execute() error { | ||
return rootCmd.Execute() | ||
} | ||
func init() { | ||
carapace.Gen(rootCmd).Standalone() | ||
|
||
rootCmd.Flags().BoolP("help", "h", false, "show this help message and exit") | ||
rootCmd.Flags().Bool("list-recipes", false, "List builtin recipe names. You can create an e-book from a") | ||
rootCmd.Flags().Bool("version", false, "show program's version number and exit") | ||
|
||
carapace.Gen(rootCmd).PositionalCompletion( | ||
carapace.ActionFiles(), | ||
carapace.Batch( | ||
carapace.ActionFiles(), | ||
carapace.ActionCallback(func(c carapace.Context) carapace.Action { | ||
if index := strings.LastIndex(c.CallbackValue, "."); index != -1 { | ||
return carapace.ActionValuesDescribed( | ||
"mobi", "Mobipocket", | ||
"epub", "Electronic Publication", | ||
"azw3", "Amazon KF8", | ||
"fb2", "Fiction Book", | ||
"htmlz", "Zipped HTML eBook", | ||
"lit", "Microsoft LIT", | ||
"lrf", "Sony LRF", | ||
"pdb", "PalmDoc Book", | ||
"pdf", "Portable Document", | ||
"pmlz", "Zipped Palm Markup Language", | ||
"rb", "Rocket eBook", | ||
"rtf", "Rich Text Format", | ||
"snb", "S Note File", | ||
"tcr", "Psion Series 3 eBook", | ||
"txt", "Plain Text File", | ||
"txtz", "Zipped Plain Text File", | ||
"zip", "Zipped File", | ||
).Invoke(c).Prefix(c.CallbackValue[:index+1]).ToA().StyleF(style.ForPathExt) | ||
} | ||
return carapace.ActionValues() | ||
}), | ||
).ToA(), | ||
) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
package main | ||
|
||
import "github.com/rsteube/carapace-bin/completers/ebook-convert_completer/cmd" | ||
|
||
func main() { | ||
cmd.Execute() | ||
} |