Skip to content

Commit

Permalink
update documentations
Browse files Browse the repository at this point in the history
  • Loading branch information
g0rbe committed Nov 15, 2022
1 parent 3cf1551 commit 9e34a34
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 6 deletions.
8 changes: 5 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ To get more info about the command: ./columbus <command> help
Commands:
lookup Lookup domain
insert Insert domain
help Print this help
help Print this help
The API key must be set in COLUMBUS_KEY environment variable!
The server URI can be changed by setting the COLUMBUS_URI environment variable.
Expand Down Expand Up @@ -60,14 +60,16 @@ Insert `<domain>` into the Columbus Database.
- On sucess, returns nothing with code 0. Duplications are silently ignored and count as a sucessful insert.
- On error, returns the error message and code 1.

When using `input` or `file`, an invalid domain does not stop the process, only print the error to stderr.

```bash
columbus insert help
```
```
Usage: ./columbus insert <domain>
If <domain> is "input", then reads domains from the standard input.
If <domain> is "file <path>" then read domains from the given file file.
If <domain> is "file <path>" then read domains from the given file.
Examples:
echo 'example.com
Expand All @@ -76,6 +78,6 @@ www.example.com' | ./columbus insert input -> Read and insert example.com and ww
./columbus insert example.com -> Insert example.com
IMPORTANT:
If "input" or "file" selected, than the domains must be newline separated (one domain per line).
If "input" or "file" selected, than the domains must be newline separated list (one domain per line).
This command requires a valid API key! Set API key in the COLUMBUS_KEY environment variable
```
8 changes: 6 additions & 2 deletions insert.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,18 +14,19 @@ func InsertHelp() {
fmt.Printf("Usage: %s insert <domain>\n", os.Args[0])
fmt.Printf("\n")
fmt.Printf("If <domain> is \"input\", then reads domains from the standard input.\n")
fmt.Printf("If <domain> is \"file <path>\" then read domains from the given file file.\n")
fmt.Printf("If <domain> is \"file <path>\" then read domains from the given file.\n")
fmt.Printf("\n")
fmt.Printf("Examples:\n")
fmt.Printf("echo 'example.com\nwww.example.com' | %s insert input -> Read and insert example.com and www.example.com\n", os.Args[0])
fmt.Printf("%s insert file /path/to/domains -> Insert domains from the file\n", os.Args[0])
fmt.Printf("%s insert example.com -> Insert example.com\n", os.Args[0])
fmt.Printf("\n")
fmt.Printf("IMPORTANT:\n")
fmt.Printf("If \"input\" or \"file\" selected, than the domains must be newline separated (one domain per line).\n")
fmt.Printf("If \"input\" or \"file\" selected, than the domains must be newline separated list (one domain per line).\n")
fmt.Printf("This command requires a valid API key! Set API key in the COLUMBUS_KEY environment variable\n")
}

// Insert domain(s) from input.
func insertInput() {

scanner := bufio.NewScanner(os.Stdin)
Expand All @@ -50,6 +51,7 @@ func insertInput() {
}
}

// Insert domain(s) from file in path.
func insertFile(path string) {

file, err := os.OpenFile(path, os.O_RDONLY, 0644)
Expand Down Expand Up @@ -81,6 +83,7 @@ func insertFile(path string) {
}
}

// Insert a single domain.
func insert(d string) {

if !domain.IsValid(d) {
Expand All @@ -107,6 +110,7 @@ func Insert() {
InsertHelp()
os.Exit(0)
}

if os.Getenv("COLUMBUS_URI") != "" {
sdk.SetURI(os.Getenv("COLUMBUS_URI"))
}
Expand Down
2 changes: 1 addition & 1 deletion main.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ var (

func main() {

if len(os.Args) == 1 {
if len(os.Args) < 2 {
HelpPrint()
os.Exit(1)
}
Expand Down

0 comments on commit 9e34a34

Please sign in to comment.