Skip to content

Commit

Permalink
feat: add Output
Browse files Browse the repository at this point in the history
  • Loading branch information
benemohamed committed Jul 26, 2023
1 parent 7aaefb1 commit e92c027
Show file tree
Hide file tree
Showing 12 changed files with 77 additions and 69 deletions.
11 changes: 7 additions & 4 deletions cmd/author.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,17 +45,20 @@ func authorRun(cmd *cobra.Command, args []string) {
return
}
if result.Data.Email != "" {
raw, _ := result.Marshal()
if init.JSON {
raw, _ := result.Marshal()
json, _ := output.DisplayJSON(string(raw))
fmt.Println(json)
return
}
if init.YAML {
raw, _ := result.Marshal()
yaml, _ := output.DisplayYAML(string(raw))
fmt.Println(yaml)
return
}
if init.Output != "" {
err := output.CreateOutput(init.Output, string(raw))
if err != nil {
fmt.Println("Error creating file:", err)
}
}
return
}
Expand Down
11 changes: 7 additions & 4 deletions cmd/count.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,17 +46,20 @@ func countRun(cmd *cobra.Command, args []string) {
return
}
if result.Data.Total > 0 {
raw, _ := result.Marshal()
if init.JSON {
raw, _ := result.Marshal()
json, _ := output.DisplayJSON(string(raw))
fmt.Println(json)
return
}
if init.YAML {
raw, _ := result.Marshal()
yaml, _ := output.DisplayYAML(string(raw))
fmt.Println(yaml)
return
}
if init.Output != "" {
err := output.CreateOutput(init.Output, string(raw))
if err != nil {
fmt.Println("Error creating file:", err)
}
}
return
}
Expand Down
11 changes: 7 additions & 4 deletions cmd/enrich.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,17 +46,20 @@ func enrichRun(cmd *cobra.Command, args []string) {
return
}
if result.Data.Email != "" {
raw, _ := result.Marshal()
if init.JSON {
raw, _ := result.Marshal()
json, _ := output.DisplayJSON(string(raw))
fmt.Println(json)
return
}
if init.YAML {
raw, _ := result.Marshal()
yaml, _ := output.DisplayYAML(string(raw))
fmt.Println(yaml)
return
}
if init.Output != "" {
err := output.CreateOutput(init.Output, string(raw))
if err != nil {
fmt.Println("Error creating file:", err)
}
}
return
}
Expand Down
11 changes: 7 additions & 4 deletions cmd/linkedin.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,17 +46,20 @@ func linkedinRun(cmd *cobra.Command, args []string) {
return
}
if result.Data.Email != "" {
raw, _ := result.Marshal()
if init.JSON {
raw, _ := result.Marshal()
json, _ := output.DisplayJSON(string(raw))
fmt.Println(json)
return
}
if init.YAML {
raw, _ := result.Marshal()
yaml, _ := output.DisplayYAML(string(raw))
fmt.Println(yaml)
return
}
if init.Output != "" {
err := output.CreateOutput(init.Output, string(raw))
if err != nil {
fmt.Println("Error creating file:", err)
}
}
return
}
Expand Down
3 changes: 0 additions & 3 deletions cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,6 @@ func init() {
rootCmd.PersistentFlags().StringVarP(&conn.Secret, "secret", "s", "", "Tomba API SECRET.")
rootCmd.PersistentFlags().StringVarP(&conn.Target, "target", "t", "", "TARGET SPECIFICATION Can pass email, Domain, URL, Linkedin URL.")
rootCmd.PersistentFlags().StringVarP(&conn.Output, "output", "o", "", "Save the results to file.")
rootCmd.PersistentFlags().BoolVarP(&conn.Pretty, "pretty", "p", true, "output pretty format.")
rootCmd.PersistentFlags().BoolVarP(&conn.Color, "color", "n", true, "disable color output.")
rootCmd.PersistentFlags().BoolVarP(&conn.JSON, "json", "j", true, "output JSON format.")
rootCmd.PersistentFlags().BoolVarP(&conn.CSV, "csv", "c", false, "output CSV format.")
rootCmd.PersistentFlags().BoolVarP(&conn.YAML, "yaml", "y", false, "output YAML format.")
}
11 changes: 7 additions & 4 deletions cmd/search.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,17 +46,20 @@ func searchRun(cmd *cobra.Command, args []string) {
return
}
if result.Meta.Total > 0 {
raw, _ := result.Marshal()
if init.JSON {
raw, _ := result.Marshal()
json, _ := output.DisplayJSON(string(raw))
fmt.Println(json)
return
}
if init.YAML {
raw, _ := result.Marshal()
yaml, _ := output.DisplayYAML(string(raw))
fmt.Println(yaml)
return
}
if init.Output != "" {
err := output.CreateOutput(init.Output, string(raw))
if err != nil {
fmt.Println("Error creating file:", err)
}
}
return
}
Expand Down
11 changes: 7 additions & 4 deletions cmd/status.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,16 +44,19 @@ func statusRun(cmd *cobra.Command, args []string) {
fmt.Println(util.ErrorIcon(), util.Red(start.ErrErrInvalidLogin.Error()))
return
}
raw, _ := result.Marshal()
if init.JSON {
raw, _ := result.Marshal()
json, _ := output.DisplayJSON(string(raw))
fmt.Println(json)
return
}
if init.YAML {
raw, _ := result.Marshal()
yaml, _ := output.DisplayYAML(string(raw))
fmt.Println(yaml)
return
}
if init.Output != "" {
err := output.CreateOutput(init.Output, string(raw))
if err != nil {
fmt.Println("Error creating file:", err)
}
}
}
11 changes: 7 additions & 4 deletions cmd/verify.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,17 +51,20 @@ func verifyRun(cmd *cobra.Command, args []string) {
fmt.Println(util.WarningIcon(), util.Yellow("Tomba is designed to contact other professionals. This email is used to create personal email addresses so we don't the verification. 💡"))
return
}
raw, _ := result.Marshal()
if init.JSON {
raw, _ := result.Marshal()
json, _ := output.DisplayJSON(string(raw))
fmt.Println(json)
return
}
if init.YAML {
raw, _ := result.Marshal()
yaml, _ := output.DisplayYAML(string(raw))
fmt.Println(yaml)
return
}
if init.Output != "" {
err := output.CreateOutput(init.Output, string(raw))
if err != nil {
fmt.Println("Error creating file:", err)
}
}
return
}
Expand Down
21 changes: 21 additions & 0 deletions pkg/output/file.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package output

import "os"

// CreateOutput creates a new file with the given filename and writes the data to it.
func CreateOutput(filename string, data string) error {
// Create a new file with the given filename
file, err := os.Create(filename)
if err != nil {
return err
}
defer file.Close()

// Write the data to the file
_, err = file.WriteString(data)
if err != nil {
return err
}

return nil
}
32 changes: 0 additions & 32 deletions pkg/output/table.go

This file was deleted.

4 changes: 3 additions & 1 deletion pkg/start/init.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ type Parameters struct {
Target string // Can pass email, Domain, URL, Linkedin URL or TXT file for bulk.
Output string
JSON bool
CSV bool
YAML bool
Color bool
Pretty bool
Expand All @@ -31,6 +30,9 @@ type Parameters struct {
func New(conn Conn) *Conn {
// Read the config file
conf, err := config.ReadConfigFile()
if conn.YAML {
conn.Parameters.JSON = false
}
if err != nil {
fmt.Println("Error reading config file:", err)
}
Expand Down
9 changes: 4 additions & 5 deletions snapcraft.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@ description: |
Tomba.io (CLI) utility to search or verify lists of email addresses in minutes can significantly improve productivity and efficiency for individuals and businesses dealing with large email databases. This utility can automate the process of checking the validity and deliverability of email addresses, saving valuable time and resources. Let's explore the features and benefits of such a CLI utility:
* Instantly locate email addresses from any website https://tomba.io/domain-search .
* Email verify to confirm an email address' authenticity https://tomba.io/email-verifier.
* Enrich email with data. https://tomba.io/enrichment https://tomba.io/enrichment.
* Instantly discover the email addresses of Linkedin URLs https://tomba.io/linkedin-finder.
* Instantly discover the email addresses of article authors https://tomba.io/author-finder.
* Email verify to confirm an email address' authenticity https://tomba.io/email-verifier .
* Enrich email with data https://tomba.io/enrichment .
* Instantly discover the email addresses of Linkedin URLs https://tomba.io/linkedin-finder .
* Instantly discover the email addresses of article authors https://tomba.io/author-finder .
This snap is built via the build.snapcraft.io service from the snapcraft.yaml definition at https://github.com/tomba-io/email to ensure source and build transparency.
issues: https://github.com/tomba-io/email/issues
Expand All @@ -20,7 +20,6 @@ grade: stable
base: core20

confinement: strict
adopt-info: email

apps:
email:
Expand Down

0 comments on commit e92c027

Please sign in to comment.