예제 #1
0
파일: maulias.go 프로젝트: tulir293/maulias
func init() {
	err := flag.Parse()
	if err != nil {
		fmt.Fprintln(os.Stderr, err)
		fmt.Fprintln(os.Stdout, help)
		os.Exit(1)
	} else if *wantHelp {
		fmt.Fprintln(os.Stdout, help)
		os.Exit(0)
	}
}
예제 #2
0
func main() {
	flag.MakeHelpFlag()
	flag.SetHelpTitles("flagtest - Test the mauflag package", "mauflag [-b] [-x] [-y] [-z] [-s STRING] [-a ARRAY VALUE] [--asd STRING]")
	fmt.Println(flag.Parse())

	if flag.CheckHelpFlag() {
		return
	}

	fmt.Println(*bf, *xb, *yb, *zb)
	fmt.Println(*str)
	fmt.Println(*def)
	for _, arg := range *array {
		fmt.Print(arg, ", ")
	}
	fmt.Print("\n")
	for _, arg := range flag.Args() {
		fmt.Print(arg, ", ")
	}
	fmt.Print("\n")
}
예제 #3
0
func main() {
	err := flag.Parse()
	flag.SetHelpTitles("lmitest - A simple program to test libmauirc.", "lmitest [-h] [-s] [-a IP ADDRESS] [-p PORT]")
	if err != nil {
		fmt.Fprintln(os.Stderr, err)
		flag.PrintHelp()
		os.Exit(1)
	} else if *wantHelp {
		flag.PrintHelp()
		os.Exit(0)
	}

	c := irc.Create("lmitest", "lmitest", irc.IPv4Address{IP: *ip, Port: *port})
	c.SetRealName("libmauirc tester")
	c.SetDebugWriter(os.Stdout)
	c.SetUseTLS(*tls)

	err = c.Connect()
	if err != nil {
		panic(err)
	}

	go c.Loop()

	term := make(chan os.Signal, 1)
	signal.Notify(term, os.Interrupt, syscall.SIGTERM)
	usr1 := make(chan os.Signal, 1)
	signal.Notify(usr1, syscall.SIGUSR1)
	usr2 := make(chan os.Signal, 1)
	signal.Notify(usr2, syscall.SIGUSR2)
	go func() {
		for {
			select {
			case <-usr1:
				c.Debugln("Disconnecting...")
				c.Disconnect()
			case <-term:
				c.Debugln("\nQuitting...")
				c.Quit()
				break
			case <-usr2:
				c.Debugln("Quitting...")
				c.Quit()
				break
			}
		}
	}()

	go func() {
		err := <-c.Errors()
		fmt.Fprintln(os.Stderr, "[Error]", err)
	}()

	reader := bufio.NewReader(os.Stdin)
	for {
		text, _ := reader.ReadString('\n')
		send := msg.ParseMessage(text)
		if strings.HasPrefix(send.Command, "CTCP_") {
			send.Trailing = ctcp.Encode(send.Command[len("CTCP_"):], send.Trailing)
			send.Command = msg.PRIVMSG
		}
		c.Send(send)
	}
}