Пример #1
0
func action(c *cli.Context) {
	args := c.Args()
	if len(args) == 0 {
		fmt.Fprintln(os.Stderr, "filename required")
		os.Exit(1)
	}
	f, err := os.Open(args[0])
	if err != nil {
		fmt.Fprintln(os.Stderr, err)
		os.Exit(1)
	}
	var lines []string
	scanner := bufio.NewScanner(f)
	for scanner.Scan() {
		lines = append(lines, scanner.Text())
	}
	if err := scanner.Err(); err != nil {
		fmt.Fprintln(os.Stderr, err)
		os.Exit(1)
	}
	option := vm.NewOption()
	if c.Bool("trace") {
		option.Trace()
	}
	result, errs := vm.Run(lines, option)
	if len(errs) != 0 {
		for _, err := range errs {
			fmt.Fprintln(os.Stderr, err)
		}
		os.Exit(1)
	}
	fmt.Print(result)
}
Пример #2
0
func action(c *cli.Context) {
	args := c.Args()
	if len(args) == 0 {
		log.Fatal("filename required")
	}
	f, err := os.Open(args[0])
	if err != nil {
		log.Fatal(err)
	}
	var lines []string
	scanner := bufio.NewScanner(f)
	for scanner.Scan() {
		lines = append(lines, scanner.Text())
	}
	if err := scanner.Err(); err != nil {
		log.Fatal(err)
	}
	result, err := vm.Run(lines, vm.NewOption())
	if err != nil {
		log.Fatal(err)
	}
	fmt.Print(result)
}