62 lines
1.1 KiB
Go
62 lines
1.1 KiB
Go
package main
|
|
|
|
import (
|
|
"addressBook/utils"
|
|
"bufio"
|
|
"fmt"
|
|
"os"
|
|
"strings"
|
|
|
|
"github.com/sirupsen/logrus"
|
|
)
|
|
|
|
func init() {
|
|
// Create a new logger
|
|
log := logrus.New()
|
|
log.SetFormatter(&logrus.TextFormatter{})
|
|
|
|
}
|
|
|
|
func main() {
|
|
// Initialize the database
|
|
utils.CreateDatabase()
|
|
fmt.Println("Welcome to your address book")
|
|
fmt.Println("---------------------")
|
|
fmt.Println("a - Add a new contact")
|
|
fmt.Println("d - Delete a contact")
|
|
fmt.Println("p - Print all contacts")
|
|
fmt.Println("q - Quit")
|
|
fmt.Println("---------------------")
|
|
|
|
reader := bufio.NewReader(os.Stdin)
|
|
line, err := reader.ReadString('\n')
|
|
line = strings.TrimSpace(line)
|
|
if err != nil {
|
|
fmt.Errorf("Error reading input: %v", err)
|
|
}
|
|
|
|
// fmt.Printf("%q", line)
|
|
|
|
if len(line) != 1 {
|
|
fmt.Println("Invalid input. Please enter a single character.")
|
|
main()
|
|
}
|
|
|
|
switch line[0] {
|
|
case 'a':
|
|
// Add a new contact
|
|
add()
|
|
case 'd':
|
|
// Delete a contact
|
|
case 'p':
|
|
// Print all contacts
|
|
case 'q':
|
|
fmt.Println("Quitting the address book.")
|
|
os.Exit(0)
|
|
default:
|
|
fmt.Println("Invalid option. Please try again.")
|
|
main()
|
|
}
|
|
|
|
}
|