Skip to content
Snippets Groups Projects
Select Git revision
  • 3d14405ed952fcc96f54fa7a41442f22870a6270
  • release default protected
  • more-testing
  • attempt-vax90b1
  • attempt-1
  • conversion protected
  • linux
  • v0.9.1 protected
  • v0.9.0 protected
9 results

main.go

Blame
  • main.go 1.53 KiB
    // Package main is the main program for bulletin.
    // It is based off the 1989 version of bulletin.
    package main
    
    import (
    	"context"
    	"fmt"
    	"os"
    
    	"git.lyda.ie/kevin/bulletin/batch"
    	"git.lyda.ie/kevin/bulletin/repl"
    	"git.lyda.ie/kevin/bulletin/this"
    
    	"github.com/urfave/cli/v3"
    )
    
    func main() {
    	cmd := &cli.Command{
    		Name:        "bulletin",
    		Usage:       "a bulletin system",
    		Description: "An interpretation of the VMS BULLETIN program.",
    		Flags: []cli.Flag{
    			&cli.StringFlag{
    				Name:     "user",
    				Aliases:  []string{"u"},
    				Usage:    "user to run bulletin as",
    				Required: true,
    			},
    			&cli.StringFlag{
    				Name:    "batch",
    				Aliases: []string{"b"},
    				Usage:   "batch command",
    			},
    		},
    		Action: func(_ context.Context, cmd *cli.Command) error {
    			user := cmd.String("user")
    			batchFlag := cmd.String("batch")
    
    			if batchFlag != "" {
    				if user != "SYSTEM" {
    					fmt.Println("ERROR: can only run batch commands as SYSTEM.")
    					os.Exit(1)
    				}
    				exitcode := 0
    				switch batchFlag {
    				case "reboot":
    					exitcode = batch.Reboot()
    				case "expire":
    					exitcode = batch.Expire()
    				case "install":
    					exitcode = batch.Install()
    				default:
    					fmt.Println("ERROR: can only run batch commands as SYSTEM.")
    					exitcode = 1
    				}
    				os.Exit(exitcode)
    			}
    
    			err := this.StartThis(user)
    			if err != nil {
    				return err
    			}
    			err = repl.Loop()
    			if err != nil {
    				return err
    			}
    			return nil
    		},
    	}
    
    	err := cmd.Run(context.Background(), os.Args)
    	if err != nil {
    		fmt.Printf("ERROR: %s.\n", err)
    	}
    }