<commit_before>// Package commands ...
package commands

import (
	"os"
	"path/filepath"
	"strings"

	"github.com/jcelliott/lumber"
	"github.com/spf13/cobra"

	"github.com/nanobox-io/nanobox/commands/registry"
	"github.com/nanobox-io/nanobox/commands/server"
	"github.com/nanobox-io/nanobox/models"
	"github.com/nanobox-io/nanobox/processors"
	"github.com/nanobox-io/nanobox/util"
	"github.com/nanobox-io/nanobox/util/config"
	"github.com/nanobox-io/nanobox/util/display"
	"github.com/nanobox-io/nanobox/util/update"
)

//
var (
	// debug mode
	debugMode bool

	// display level debug
	displayDebugMode bool

	// display level trace
	displayTraceMode bool

	//
	internalCommand bool

	//
	endpoint string

	// NanoboxCmd ...
	NanoboxCmd = &cobra.Command{
		Use:   "",
		Short: "",
		Long:  ``,
		PersistentPreRun: func(ccmd *cobra.Command, args []string) {

			// report the command to nanobox
			processors.SubmitLog(strings.Replace(ccmd.CommandPath(), "nanobox ", "", 1))
			// mixpanel.Report(strings.Replace(ccmd.CommandPath(), "nanobox ", "", 1))

			// alert the user if an update is needed
			update.Check()

			configModel, _ := models.LoadConfig()

			// TODO: look into global messaging
			if internalCommand {
				registry.Set("internal", internalCommand)
				// setup a file logger, this will be replaced in verbose mode.
				fileLogger, _ := lumber.NewAppendLogger(filepath.ToSlash(filepath.Join(config.GlobalDir(), "nanobox.log")))
				lumber.SetLogger(fileLogger)

			} else {
				// We should only allow admin in 3 carse
				// 1 cimode
				// 2 server is running
				// 3 configuring
				if util.IsPrivileged() &&
					!configModel.CIMode &&
					!strings.Contains(ccmd.CommandPath(), " config") &&
					!strings.Contains(ccmd.CommandPath(), "server") {
					// if it is not an internal command (starting the server requires privilages)
					// we wont run nanobox as privilage
					display.UnexpectedPrivilage()
					os.Exit(1)
				}
			}<commit_msg>be specific about the config command<commit_after>// Package commands ...
package commands

import (
	"os"
	"path/filepath"
	"strings"

	"github.com/jcelliott/lumber"
	"github.com/spf13/cobra"

	"github.com/nanobox-io/nanobox/commands/registry"
	"github.com/nanobox-io/nanobox/commands/server"
	"github.com/nanobox-io/nanobox/models"
	"github.com/nanobox-io/nanobox/processors"
	"github.com/nanobox-io/nanobox/util"
	"github.com/nanobox-io/nanobox/util/config"
	"github.com/nanobox-io/nanobox/util/display"
	"github.com/nanobox-io/nanobox/util/update"
)

//
var (
	// debug mode
	debugMode bool

	// display level debug
	displayDebugMode bool

	// display level trace
	displayTraceMode bool

	//
	internalCommand bool

	//
	endpoint string

	// NanoboxCmd ...
	NanoboxCmd = &cobra.Command{
		Use:   "",
		Short: "",
		Long:  ``,
		PersistentPreRun: func(ccmd *cobra.Command, args []string) {
			// report the command to nanobox
			processors.SubmitLog(strings.Replace(ccmd.CommandPath(), "nanobox ", "", 1))
			// mixpanel.Report(strings.Replace(ccmd.CommandPath(), "nanobox ", "", 1))

			// alert the user if an update is needed
			update.Check()

			configModel, _ := models.LoadConfig()

			// TODO: look into global messaging
			if internalCommand {
				registry.Set("internal", internalCommand)
				// setup a file logger, this will be replaced in verbose mode.
				fileLogger, _ := lumber.NewAppendLogger(filepath.ToSlash(filepath.Join(config.GlobalDir(), "nanobox.log")))
				lumber.SetLogger(fileLogger)

			} else {
				// We should only allow admin in 3 carse
				// 1 cimode
				// 2 server is running
				// 3 configuring
				fullCmd := strings.Join(os.Args, " ")
				if util.IsPrivileged() &&
					!configModel.CIMode &&
					!strings.Contains(fullCmd, "set ci") &&
					!strings.Contains(ccmd.CommandPath(), "server") {
					// if it is not an internal command (starting the server requires privilages)
					// we wont run nanobox as privilage
					display.UnexpectedPrivilage()
					os.Exit(1)
				}
			}
{'fraction_non_alphanumeric': 0.13691073219658978, 'fraction_numerical': 0.004513540621865597, 'mean_word_length': 3.2572038420490927, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, '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': '726927', 'n_tokens_mistral': 1595, 'n_tokens_neox': 1327, 'n_words': 286}