Skip to content

Commit 9faa321

Browse files
committed
Remove state init language inference.
It was too confusing. Just go back to requiring the `--language` argument.
1 parent 9dabacc commit 9faa321

File tree

3 files changed

+1
-60
lines changed

3 files changed

+1
-60
lines changed

internal/locale/locales/en-us.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -876,7 +876,7 @@ deploy_uninstall_success:
876876
err_arg_required:
877877
other: "The following argument is required:\n Name: [NOTICE]{{.V0}}[/RESET]\n Description: [NOTICE]{{.V1}}[/RESET]"
878878
err_init_no_language:
879-
other: "A project has not been set using 'state use'. You must include the [NOTICE]language[/RESET] argument. For more help, run '[ACTIONABLE]state init --help[/RESET]'."
879+
other: "You must include the [NOTICE]language[/RESET] argument. For more help, run '[ACTIONABLE]state init --help[/RESET]'."
880880
platform_added:
881881
other: "[NOTICE]{{.V0}}[/RESET] has been added."
882882
platform_removed:

internal/runners/initialize/init.go

Lines changed: 0 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -96,34 +96,6 @@ func New(prime primeable) *Initialize {
9696
return &Initialize{prime, prime.Auth(), prime.Config(), prime.Output(), prime.Analytics(), prime.SvcModel()}
9797
}
9898

99-
// inferLanguage tries to infer a reasonable default language from the project currently in use
100-
// (i.e. `state use show`).
101-
// Error handling is not necessary because it's an input error to not include a language to
102-
// `state init`. We're just trying to infer one as a convenience to the user.
103-
func inferLanguage(config projectfile.ConfigGetter, auth *authentication.Auth) (string, string, bool) {
104-
defaultProjectDir := config.GetString(constants.GlobalDefaultPrefname)
105-
if defaultProjectDir == "" {
106-
return "", "", false
107-
}
108-
defaultProj, err := project.FromPath(defaultProjectDir)
109-
if err != nil {
110-
return "", "", false
111-
}
112-
commitID, err := localcommit.Get(defaultProj.Dir())
113-
if err != nil {
114-
multilog.Error("Unable to get local commit: %v", errs.JoinMessage(err))
115-
return "", "", false
116-
}
117-
if commitID == "" {
118-
return "", "", false
119-
}
120-
lang, err := model.FetchLanguageForCommit(commitID, auth)
121-
if err != nil {
122-
return "", "", false
123-
}
124-
return lang.Name, lang.Version, true
125-
}
126-
12799
func (r *Initialize) Run(params *RunParams) (rerr error) {
128100
defer func() { runtime_runbit.RationalizeSolveError(r.prime.Project(), r.auth, &rerr) }()
129101

@@ -181,10 +153,6 @@ func (r *Initialize) Run(params *RunParams) (rerr error) {
181153
languageVersion = langParts[1]
182154
}
183155
} else {
184-
languageName, languageVersion, _ = inferLanguage(r.config, r.auth)
185-
}
186-
187-
if languageName == "" {
188156
return errNoLanguage
189157
}
190158

test/integration/init_int_test.go

Lines changed: 0 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -114,33 +114,6 @@ func (suite *InitIntegrationTestSuite) TestInit_NoLanguage() {
114114
ts.IgnoreLogErrors()
115115
}
116116

117-
func (suite *InitIntegrationTestSuite) TestInit_InferLanguageFromUse() {
118-
suite.OnlyRunForTags(tagsuite.Init)
119-
ts := e2e.New(suite.T(), false)
120-
defer ts.Close()
121-
ts.LoginAsPersistentUser()
122-
123-
cp := ts.Spawn("config", "set", constants.AsyncRuntimeConfig, "true")
124-
cp.ExpectExitCode(0)
125-
126-
cp = ts.Spawn("checkout", "ActiveState-CLI/small-python")
127-
cp.Expect("Checked out project")
128-
cp.ExpectExitCode(0)
129-
130-
cp = ts.Spawn("use", "small-python")
131-
cp.Expect("Switched to project", e2e.RuntimeSourcingTimeoutOpt)
132-
cp.ExpectExitCode(0)
133-
134-
pname := strutils.UUID()
135-
namespace := fmt.Sprintf("%s/%s", e2e.PersistentUsername, pname)
136-
cp = ts.Spawn("init", namespace)
137-
cp.Expect("successfully initialized")
138-
cp.ExpectExitCode(0)
139-
ts.NotifyProjectCreated(e2e.PersistentUsername, pname.String())
140-
141-
suite.Contains(string(fileutils.ReadFileUnsafe(filepath.Join(ts.Dirs.Work, constants.ConfigFileName))), "language: python3")
142-
}
143-
144117
func (suite *InitIntegrationTestSuite) TestInit_NotAuthenticated() {
145118
suite.OnlyRunForTags(tagsuite.Init)
146119
ts := e2e.New(suite.T(), false)

0 commit comments

Comments
 (0)