<commit_before>package commands

import (
	"appstax-cli/appstax/account"
	"appstax-cli/appstax/config"
	"appstax-cli/appstax/fail"
	"appstax-cli/appstax/log"
	"appstax-cli/appstax/template"
	"appstax-cli/appstax/term"
	"errors"
	"fmt"
	"github.com/codegangsta/cli"
	"os"
	"strings"
)

func DoInit(c *cli.Context) {
	useOptions(c)
	loginIfNeeded()

	app, err := selectApp()
	if err != nil {
		return
	}

	tpl := selectTemplate()

	pub := "./public"
	if tpl.Name == "none" {
		term.Section()
		pub = selectPublicDir()
	}
	writeConfig(app, pub)

	if !strings.HasPrefix(tpl.Name, "ios/") {
		createPublicDir()
	}

	if tpl.Name != "none" {
		term.Section()
		term.Println("Setting up template... ")
		template.Install(tpl)
		term.Println("Done.")
	}

	term.Section()
	selectSubdomain(app.AppID)

	term.Section()
	term.Println("All done!")
	term.Println("Now run 'appstax deploy' when you are ready to upload your public files.")
}

func selectApp() (account.App, error) {
	apps, _ := account.GetUserApps()
	selected := 0
	if len(apps) == 0 {
		term.Section()
		term.Println("You don't have access to any apps!")
		term.Println("Create one on appstax.com and come back here.")
		return account.App{}, errors.New("Account has no apps")
	} else if len(apps) > 1 {
		term.Section()
		term.Println("Choose which app to configure:")
		for i, app := range apps {
			term.Printf("  %d) %s\n", i+1, app.AppName)
		}
		term.Section()
		selected = -1 + term.GetInt(fmt.Sprintf("Please select (1-%d)", len(apps)))
	}
	return apps[selected], nil
}

func selectTemplate() template.Template {
	templates := template.All()

	term.Section()
	term.Println("Choose a template for you app:")
	for i, template := range templates {
		term.Printf("  %d) %s\n", i+1, template.Label)
	}

	term.Section()
	for {
		selected := -1 + term.GetInt(fmt.Sprintf("Please select (1-%d)", len(templates)))
		if selected >= 0 && selected < len(templates) {
			return templates[selected]
		}
	}
}

func selectPublicDir() string {
	dir := term.GetString("Select deployable directory [default: ./public]")
	if dir == "" {
		dir = "./public"
	}
	return dir
}<commit_msg>Prompt to select app also when there is only one to choose from.<commit_after>package commands

import (
	"appstax-cli/appstax/account"
	"appstax-cli/appstax/config"
	"appstax-cli/appstax/fail"
	"appstax-cli/appstax/log"
	"appstax-cli/appstax/template"
	"appstax-cli/appstax/term"
	"errors"
	"fmt"
	"github.com/codegangsta/cli"
	"os"
	"strings"
)

func DoInit(c *cli.Context) {
	useOptions(c)
	loginIfNeeded()

	app, err := selectApp()
	if err != nil {
		return
	}

	tpl := selectTemplate()

	pub := "./public"
	if tpl.Name == "none" {
		term.Section()
		pub = selectPublicDir()
	}
	writeConfig(app, pub)

	if !strings.HasPrefix(tpl.Name, "ios/") {
		createPublicDir()
	}

	if tpl.Name != "none" {
		term.Section()
		term.Println("Setting up template... ")
		template.Install(tpl)
		term.Println("Done.")
	}

	term.Section()
	selectSubdomain(app.AppID)

	term.Section()
	term.Println("All done!")
	term.Println("Now run 'appstax deploy' when you are ready to upload your public files.")
}

func selectApp() (account.App, error) {
	apps, _ := account.GetUserApps()
	selected := -1
	if len(apps) == 0 {
		term.Section()
		term.Println("You don't have access to any apps!")
		term.Println("Create one on appstax.com and come back here.")
		return account.App{}, errors.New("Account has no apps")
	} else {
		term.Section()
		term.Println("Choose which app to configure:")
		for i, app := range apps {
			term.Printf("  %d) %s\n", i+1, app.AppName)
		}
		term.Section()
		for selected < 0 || selected >= len(apps) {
			selected = -1 + term.GetInt(fmt.Sprintf("Please select (1-%d)", len(apps)))
		}
	}
	return apps[selected], nil
}

func selectTemplate() template.Template {
	templates := template.All()

	term.Section()
	term.Println("Choose a template for you app:")
	for i, template := range templates {
		term.Printf("  %d) %s\n", i+1, template.Label)
	}

	term.Section()
	for {
		selected := -1 + term.GetInt(fmt.Sprintf("Please select (1-%d)", len(templates)))
		if selected >= 0 && selected < len(templates) {
			return templates[selected]
		}
	}
}

func selectPublicDir() string {
	dir := term.GetString("Select deployable directory [default: ./public]")
	if dir == "" {
		dir = "./public"
	}
	return dir
}
{'fraction_non_alphanumeric': 0.16751269035532995, 'fraction_numerical': 0.0046146746654360865, 'mean_word_length': 3.805986696230599, 'pattern_counts': {'":': 0, '<': 6, '<?xml version=': 0, '>': 7, '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': '7285635', 'n_tokens_mistral': 1685, 'n_tokens_neox': 1603, 'n_words': 382}