diff --git a/README.md b/README.md index bb38514..82f3c5e 100644 --- a/README.md +++ b/README.md @@ -53,6 +53,16 @@ Choose an option: 0 Success! ``` +Another way to purchase domains is actually to use output from the `list` command. This is useful if you want to leave AIRMASTER alone for a while while you grab a coffee, or while you're reading documentation on Windows Me because your target is using that for some reason. + +``` +AIRMASTER list --file ~/Downloads/domains.txt > /tmp/available + +*20 minuites later* - Edit list from /tmp/available as you'd like to + +AIRMASTER purchase --list /tmp/available +``` + The help *should* be obvious, so if you are stuck, try using `AIRMASTER --help`. (Although if you are still stuck, please create an issue) ## Config diff --git a/cmd/list.go b/cmd/list.go index 423cf25..a39a1a9 100644 --- a/cmd/list.go +++ b/cmd/list.go @@ -2,6 +2,7 @@ package cmd import ( "fmt" + "os" "github.com/t94j0/AIRMASTER/domain" @@ -70,6 +71,9 @@ func init() { listCmd.Flags().StringP("file", "f", "", "File used for checking domains") listCmd.Flags().StringSliceP("keyword", "k", nil, "Keyword for searching domains") listCmd.Flags().Int("pages", 10, "How many pages of data to get when using the --keyword option") - viper.BindPFlags(listCmd.Flags()) + if err := viper.BindPFlags(listCmd.Flags()); err != nil { + fmt.Fprintln(os.Stderr, "Error binding flags:", err) + os.Exit(1) + } } diff --git a/cmd/purchase.go b/cmd/purchase.go new file mode 100644 index 0000000..e0d9414 --- /dev/null +++ b/cmd/purchase.go @@ -0,0 +1,71 @@ +package cmd + +import ( + "bufio" + "fmt" + "net/url" + "os" + "strings" + + "github.com/spf13/cobra" + "github.com/spf13/viper" + "github.com/t94j0/AIRMASTER/domain" +) + +// purchaseCmd represents the purchase command +var purchaseCmd = &cobra.Command{ + Use: "purchase", + Short: "Purchase domains straight after listing", + Long: `Purchase should be used if you just want to purchase one domain or from a +previous listing. This can be more efficent if you want to leave the "list" +command running for a long time. + +Example: AIRMASTER purchase --domain "maxh.io" + or + AIRMASTER list --file ./domains.txt > categorized_domains.txt + cat categorized_domains.txt | AIRMASTER purchase`, + Run: func(cmd *cobra.Command, args []string) { + if viper.GetString("domain") != "" { + singleDomain := domain.NewDomain(viper.GetString("domain"), "") + singleDomain.PromptPurchase() + } else if viper.GetString("list") != "" { + file, err := os.Open(viper.GetString("list")) + if err != nil { + fmt.Fprintln(os.Stderr, "Could not open file:", err) + return + } + scanner := bufio.NewScanner(file) + + for scanner.Scan() { + // Remove final newline character + urlLine := strings.Trim(scanner.Text(), "\n") + // Get just the URL (http://maxh.io) + urlCat := strings.Split(urlLine, "-") + if len(urlCat) != 2 { + fmt.Printf("URL \"%s\" is malformed. Please use output from `AIRMASTER list`\n", urlLine) + continue + } + urlLine = strings.TrimRight(urlCat[0], " ") + categorization := strings.TrimLeft(urlCat[1], " ") + urlObj, err := url.Parse(urlLine) + if err != nil { + fmt.Println("Failed parsing URL:", urlLine) + continue + } + singleDomain := domain.NewDomain(urlObj.Host, categorization) + singleDomain.PromptPurchase() + } + } + }, +} + +func init() { + RootCmd.AddCommand(purchaseCmd) + purchaseCmd.Flags().StringP("domain", "d", "", "Used to purchase a single domain") + purchaseCmd.Flags().StringP("list", "l", "", "Specify output from `list` to get a purchase prompt") + + if err := viper.BindPFlags(purchaseCmd.Flags()); err != nil { + fmt.Println("Error binding flags:", err) + os.Exit(1) + } +} diff --git a/cmd/root.go b/cmd/root.go index b53ee76..6f2abca 100644 --- a/cmd/root.go +++ b/cmd/root.go @@ -57,7 +57,7 @@ func initConfig() { // If a config file is found, read it in. if err := viper.ReadInConfig(); err == nil { - fmt.Println("Using config file:", viper.ConfigFileUsed()) + fmt.Fprintln(os.Stderr, "Using config file:", viper.ConfigFileUsed()) } else { fmt.Println(err) os.Exit(1) diff --git a/domain/check_domain.go b/domain/check_domain.go index 86e5cdd..eaa93d7 100644 --- a/domain/check_domain.go +++ b/domain/check_domain.go @@ -74,7 +74,7 @@ func CheckDomain(domain string, client *http.Client) error { newDomain.PromptPurchase() return nil } - fmt.Println("Found:", cat.URL, "-", categorization) + fmt.Println(cat.URL, "-", categorization) return nil } default: diff --git a/domain/purchase.go b/domain/purchase.go index ae25b96..f5b3e47 100644 --- a/domain/purchase.go +++ b/domain/purchase.go @@ -44,6 +44,7 @@ func (d *Domain) PromptPurchase() { // Get all registrars that have the domain available availableRegistrars, prices := getAvailability(d.URL, allRegistrars) if len(availableRegistrars) == 0 { + fmt.Fprintln(os.Stderr, "No available registrars found for domain:", d.URL) return } @@ -77,11 +78,11 @@ func (d *Domain) PromptPurchase() { input = strings.Trim(input, "\n") choice, err := strconv.Atoi(input) if err != nil { - fmt.Println("Please input a number...") + fmt.Fprintln(os.Stderr, "Please input a number...") continue } if len(availableRegistrars) < choice || choice < -1 { - fmt.Println("Not a choice") + fmt.Fprintln(os.Stderr, "Not a choice") continue }