<commit_before>// Copyright 2016 The Upspin Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.

package main

import (
	"bufio"
	"flag"
	"fmt"
	"os"
	"strings"
)

func (s *State) shell(args ...string) {
	const help = `
Shell runs an interactive session for upspin subcommands.
When running the shell, the leading "upspin" is assumed on each command.
`
	fs := flag.NewFlagSet("shell", flag.ExitOnError)
	promptFlag := fs.String("prompt", "u> ", "interactive prompt")
	verbose := fs.Bool("v", false, "verbose; print to stderr each command before execution")
	s.parseFlags(fs, args, help, "shell [-v] [-prompt=<prompt_string>]")
	if fs.NArg() != 0 {
		fs.Usage()
	}
	prompt := func() {
		if len(*promptFlag) > 0 {
			fmt.Print(*promptFlag)
		}
	}
	s.interactive = true
	defer func() { s.interactive = false }()
	scanner := bufio.NewScanner(os.Stdin)
	for prompt(); scanner.Scan(); prompt() {
		s.exec(scanner.Text(), *verbose)
	}
	if scanner.Err() != nil {
		s.exit(scanner.Err())
	}
}

func (s *State) exec(line string, verbose bool) {
	defer func() {
		err := recover()<commit_msg>cmd/upspin: put username in the prompt<commit_after>// Copyright 2016 The Upspin Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.

package main

import (
	"bufio"
	"flag"
	"fmt"
	"os"
	"strings"
)

func (s *State) shell(args ...string) {
	const promptPlaceholder = "<username>"
	const help = `
Shell runs an interactive session for upspin subcommands.
When running the shell, the leading "upspin" is assumed on each command.
`
	fs := flag.NewFlagSet("shell", flag.ExitOnError)
	promptFlag := fs.String("prompt", promptPlaceholder, "interactive `prompt`")
	verbose := fs.Bool("v", false, "verbose; print to stderr each command before execution")
	s.parseFlags(fs, args, help, "shell [-v] [-prompt=<prompt_string>]")
	if fs.NArg() != 0 {
		fs.Usage()
	}
	prompt := func() {
		if len(*promptFlag) > 0 {
			fmt.Print(*promptFlag)
		}
	}
	if *promptFlag == promptPlaceholder {
		*promptFlag = string(s.context.UserName()) + ">"
	}
	s.interactive = true
	defer func() { s.interactive = false }()
	scanner := bufio.NewScanner(os.Stdin)
	for prompt(); scanner.Scan(); prompt() {
		s.exec(scanner.Text(), *verbose)
	}
	if scanner.Err() != nil {
		s.exit(scanner.Err())
	}
}

func (s *State) exec(line string, verbose bool) {
	defer func() {
		err := recover()
{'fraction_non_alphanumeric': 0.155724579663731, 'fraction_numerical': 0.004803843074459567, 'mean_word_length': 3.9780876494023905, 'pattern_counts': {'":': 0, '<': 6, '<?xml version=': 0, '>': 10, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3581084', 'n_tokens_mistral': 910, 'n_tokens_neox': 855, 'n_words': 266}