From 3d3c27f68815d6ceb4ac67ada7cbb9d6caacdfe3 Mon Sep 17 00:00:00 2001 From: tyru Date: Wed, 3 Jan 2018 04:30:52 +0900 Subject: [PATCH] Remove "volt profile use" command (fix #163) --- CMDREF.md | 7 --- README.md | 4 -- cmd/builder/base.go | 16 +++---- cmd/builder/copy.go | 4 +- cmd/builder/symlink.go | 4 +- cmd/help.go | 4 -- cmd/profile.go | 106 +---------------------------------------- cmd/profile_test.go | 28 +++-------- lockjson/lockjson.go | 4 -- 9 files changed, 19 insertions(+), 158 deletions(-) diff --git a/CMDREF.md b/CMDREF.md index 2a867d6f..fe37a2cb 100644 --- a/CMDREF.md +++ b/CMDREF.md @@ -259,10 +259,6 @@ Command profile rm [-current | {name}] {repository} [{repository2} ...] Remove one or more repositories from profile {name}. - profile use [-current | {name}] vimrc [true | false] - profile use [-current | {name}] gvimrc [true | false] - Set vimrc / gvimrc flag to true or false. - Quick example $ volt profile list # default profile is "default" * default @@ -284,9 +280,6 @@ Quick example $ volt profile rm foo tyru/caw.vim # disable loading tyru/caw.vim on "foo" profile $ volt profile destroy foo # will delete profile "foo" - - $ volt profile use -current vimrc false # Disable installing vimrc on current profile on "volt build" - $ volt profile use default gvimrc true # Enable installing gvimrc on profile default on "volt build" ``` # volt rm diff --git a/README.md b/README.md index f0293bc4..e10b6fe1 100644 --- a/README.md +++ b/README.md @@ -63,10 +63,6 @@ Command profile rm {name} {repository} [{repository2} ...] Remove one or more repositories to profile - profile use [-current | {name}] vimrc [true | false] - profile use [-current | {name}] gvimrc [true | false] - Set vimrc / gvimrc flag to true or false. - build [-full] Build ~/.vim/pack/volt/ directory diff --git a/cmd/builder/base.go b/cmd/builder/base.go index 58a1ce71..d82f4271 100644 --- a/cmd/builder/base.go +++ b/cmd/builder/base.go @@ -19,7 +19,7 @@ import ( type BaseBuilder struct{} -func (builder *BaseBuilder) installVimrcAndGvimrc(profileName, vimrcPath, gvimrcPath string, useVimrc, useGvimrc bool) error { +func (builder *BaseBuilder) installVimrcAndGvimrc(profileName, vimrcPath, gvimrcPath string) error { // Save old vimrc file as {vimrc}.bak vimrcInfo, err := os.Stat(vimrcPath) if err != nil && !os.IsNotExist(err) { @@ -39,7 +39,6 @@ func (builder *BaseBuilder) installVimrcAndGvimrc(profileName, vimrcPath, gvimrc profileName, pathutil.ProfileVimrc, vimrcPath, - useVimrc, ) if err != nil { return err @@ -50,7 +49,6 @@ func (builder *BaseBuilder) installVimrcAndGvimrc(profileName, vimrcPath, gvimrc profileName, pathutil.ProfileGvimrc, gvimrcPath, - useGvimrc, ) if err != nil { // Restore old vimrc @@ -70,7 +68,7 @@ func (builder *BaseBuilder) installVimrcAndGvimrc(profileName, vimrcPath, gvimrc return nil } -func (builder *BaseBuilder) installRCFile(profileName, srcRCFileName, dst string, install bool) error { +func (builder *BaseBuilder) installRCFile(profileName, srcRCFileName, dst string) error { src := filepath.Join(pathutil.RCDir(profileName), srcRCFileName) // Return error if destination file does not have magic comment @@ -90,8 +88,8 @@ func (builder *BaseBuilder) installRCFile(profileName, srcRCFileName, dst string return errors.New("failed to remove " + dst) } - // Skip if use_vimrc/use_gvimrc is false or rc file does not exist - if !install || !pathutil.Exists(src) { + // Skip if rc file does not exist + if !pathutil.Exists(src) { return nil } @@ -165,17 +163,17 @@ type actionReposResult struct { files buildinfo.FileMap } -func (builder *BaseBuilder) getCurrentProfileAndReposList(lockJSON *lockjson.LockJSON) (*lockjson.Profile, lockjson.ReposList, error) { +func (builder *BaseBuilder) getCurrentReposList(lockJSON *lockjson.LockJSON) (lockjson.ReposList, error) { // Find current profile profile, err := lockJSON.Profiles.FindByName(lockJSON.CurrentProfileName) if err != nil { // this must not be occurred because lockjson.Read() // validates that the matching profile exists - return nil, nil, err + return nil, err } reposList, err := lockJSON.GetReposListByProfile(profile) - return profile, reposList, err + return reposList, err } func (builder *BaseBuilder) helptags(reposPath, vimExePath string) error { diff --git a/cmd/builder/copy.go b/cmd/builder/copy.go index e32eb4f2..b3c0d7c6 100644 --- a/cmd/builder/copy.go +++ b/cmd/builder/copy.go @@ -37,7 +37,7 @@ func (builder *copyBuilder) Build(buildInfo *buildinfo.BuildInfo, buildReposMap } // Get current profile's repos list - profile, reposList, err := builder.getCurrentProfileAndReposList(lockJSON) + reposList, err := builder.getCurrentReposList(lockJSON) if err != nil { return err } @@ -48,7 +48,7 @@ func (builder *copyBuilder) Build(buildInfo *buildinfo.BuildInfo, buildReposMap vimrcPath := filepath.Join(vimDir, pathutil.Vimrc) gvimrcPath := filepath.Join(vimDir, pathutil.Gvimrc) err = builder.installVimrcAndGvimrc( - lockJSON.CurrentProfileName, vimrcPath, gvimrcPath, profile.UseVimrc, profile.UseGvimrc, + lockJSON.CurrentProfileName, vimrcPath, gvimrcPath, ) if err != nil { return err diff --git a/cmd/builder/symlink.go b/cmd/builder/symlink.go index 0de65043..9e02dcda 100644 --- a/cmd/builder/symlink.go +++ b/cmd/builder/symlink.go @@ -34,7 +34,7 @@ func (builder *symlinkBuilder) Build(buildInfo *buildinfo.BuildInfo, buildReposM if err != nil { return errors.New("could not read lock.json: " + err.Error()) } - profile, reposList, err := builder.getCurrentProfileAndReposList(lockJSON) + reposList, err := builder.getCurrentReposList(lockJSON) if err != nil { return err } @@ -45,7 +45,7 @@ func (builder *symlinkBuilder) Build(buildInfo *buildinfo.BuildInfo, buildReposM vimrcPath := filepath.Join(vimDir, pathutil.Vimrc) gvimrcPath := filepath.Join(vimDir, pathutil.Gvimrc) err = builder.installVimrcAndGvimrc( - lockJSON.CurrentProfileName, vimrcPath, gvimrcPath, profile.UseVimrc, profile.UseGvimrc, + lockJSON.CurrentProfileName, vimrcPath, gvimrcPath, ) if err != nil { return err diff --git a/cmd/help.go b/cmd/help.go index 520cf667..1e4d519b 100644 --- a/cmd/help.go +++ b/cmd/help.go @@ -80,10 +80,6 @@ Command profile rm {name} {repository} [{repository2} ...] Remove one or more repositories to profile - profile use [-current | {name}] vimrc [true | false] - profile use [-current | {name}] gvimrc [true | false] - Set vimrc / gvimrc flag to true or false. - build [-full] Build ~/.vim/pack/volt/ directory diff --git a/cmd/profile.go b/cmd/profile.go index 87218880..a6aef886 100644 --- a/cmd/profile.go +++ b/cmd/profile.go @@ -5,7 +5,6 @@ import ( "flag" "fmt" "os" - "strconv" "github.com/vim-volt/volt/lockjson" "github.com/vim-volt/volt/logger" @@ -57,10 +56,6 @@ Command profile rm [-current | {name}] {repository} [{repository2} ...] Remove one or more repositories from profile {name}. - profile use [-current | {name}] vimrc [true | false] - profile use [-current | {name}] gvimrc [true | false] - Set vimrc / gvimrc flag to true or false. - Quick example $ volt profile list # default profile is "default" * default @@ -81,10 +76,7 @@ Quick example $ volt disable tyru/caw.vim # disable loading tyru/caw.vim on current profile $ volt profile rm foo tyru/caw.vim # disable loading tyru/caw.vim on "foo" profile - $ volt profile destroy foo # will delete profile "foo" - - $ volt profile use -current vimrc false # Disable installing vimrc on current profile on "volt build" - $ volt profile use default gvimrc true # Enable installing gvimrc on profile default on "volt build"` + "\n\n") + $ volt profile destroy foo # will delete profile "foo"` + "\n\n") cmd.helped = true } return fs @@ -119,8 +111,6 @@ func (cmd *profileCmd) Run(args []string) int { err = cmd.doAdd(args[1:]) case "rm": err = cmd.doRm(args[1:]) - case "use": - err = cmd.doUse(args[1:]) default: logger.Error("unknown subcommand: " + subCmd) return 11 @@ -252,8 +242,6 @@ func (cmd *profileCmd) doShow(args []string) error { } fmt.Println("name:", profile.Name) - fmt.Println("use vimrc:", profile.UseVimrc) - fmt.Println("use gvimrc:", profile.UseGvimrc) fmt.Println("repos path:") for _, reposPath := range profile.ReposPath { hash, err := getReposHEAD(reposPath) @@ -316,8 +304,6 @@ func (cmd *profileCmd) doNew(args []string) error { lockJSON.Profiles = append(lockJSON.Profiles, lockjson.Profile{ Name: profileName, ReposPath: make([]string, 0), - UseVimrc: true, - UseGvimrc: true, }) // Write to lock.json @@ -581,93 +567,3 @@ func (*profileCmd) transactProfile(lockJSON *lockjson.LockJSON, profileName stri } return lockJSON, nil } - -func (cmd *profileCmd) doUse(args []string) error { - // Validate arguments - if len(args) != 3 { - cmd.FlagSet().Usage() - logger.Error("'volt profile use' receives profile name, rc name, value.") - return nil - } - if args[1] != "vimrc" && args[1] != "gvimrc" { - cmd.FlagSet().Usage() - logger.Error("volt profile use: Please specify \"vimrc\" or \"gvimrc\" to the 2nd argument") - return nil - } - if args[2] != "true" && args[2] != "false" { - cmd.FlagSet().Usage() - logger.Error("volt profile use: Please specify \"true\" or \"false\" to the 3rd argument") - return nil - } - - // Read lock.json - lockJSON, err := lockjson.Read() - if err != nil { - return errors.New("failed to read lock.json: " + err.Error()) - } - - // Convert arguments - var profileName string - var rcName string - var value bool - if args[0] == "-current" { - profileName = lockJSON.CurrentProfileName - } else { - profileName = args[0] - } - rcName = args[1] - if args[2] == "true" { - value = true - } else { - value = false - } - - // Look up specified profile - profile, err := lockJSON.Profiles.FindByName(profileName) - if err != nil { - return err - } - - // Begin transaction - err = transaction.Create() - if err != nil { - return err - } - defer transaction.Remove() - - // Set use_vimrc / use_gvimrc flag - changed := false - if rcName == "vimrc" { - if profile.UseVimrc != value { - logger.Infof("Set vimrc flag of profile '%s' to '%s'", profileName, strconv.FormatBool(value)) - profile.UseVimrc = value - changed = true - } else { - logger.Warnf("vimrc flag of profile '%s' is already '%s'", profileName, strconv.FormatBool(value)) - } - } else { - if profile.UseGvimrc != value { - logger.Infof("Set gvimrc flag of profile '%s' to '%s'", profileName, strconv.FormatBool(value)) - profile.UseGvimrc = value - changed = true - } else { - logger.Warnf("gvimrc flag of profile '%s' is already '%s'", profileName, strconv.FormatBool(value)) - } - } - - if changed { - // Write to lock.json - err = lockJSON.Write() - if err != nil { - return err - } - } - - // Build ~/.vim/pack/volt dir - err = (&buildCmd{}).doBuild(false) - if err != nil { - return errors.New("could not build " + pathutil.VimVoltDir() + ": " + err.Error()) - } - - return nil -} diff --git a/cmd/profile_test.go b/cmd/profile_test.go index d28a8f60..7418ec23 100644 --- a/cmd/profile_test.go +++ b/cmd/profile_test.go @@ -121,13 +121,11 @@ func TestVoltProfileSet(t *testing.T) { // Checks: // (a) Output has profile name -// (b) Output has "use vimrc" -// (c) Output has "use gvimrc" -// (d) Output has "repos path" +// (b) Output has "repos path" // -// * Run `volt profile show ` (`` is existing profile) (A, B, a, b, c, d) -// * Run `volt profile show -current` (A, B, a, b, c, d) -// * Run `volt profile show ` (`` is non-existing profile) (!A, !B, !a, !b, !c, !d) +// * Run `volt profile show ` (`` is existing profile) (A, B, a, b) +// * Run `volt profile show -current` (A, B, a, b) +// * Run `volt profile show ` (`` is non-existing profile) (!A, !B, !a, !b) func TestVoltProfileShow(t *testing.T) { t.Run("Run `volt profile show ` (`` is existing profile)", func(t *testing.T) { // =============== setup =============== // @@ -140,17 +138,11 @@ func TestVoltProfileShow(t *testing.T) { // (A, B) testutil.SuccessExit(t, out, err) - // (a, b, c, d) + // (a, b) outstr := string(out) if !strings.Contains(outstr, "name: default\n") { t.Errorf("Expected 'name: default' line, but got: %s", outstr) } - if !strings.Contains(outstr, "use vimrc: true\n") { - t.Errorf("Expected 'use vimrc: true' line, but got: %s", outstr) - } - if !strings.Contains(outstr, "use gvimrc: true\n") { - t.Errorf("Expected 'use gvimrc: true' line, but got: %s", outstr) - } if !strings.Contains(outstr, "repos path:\n") { t.Errorf("Expected 'repos path:' line, but got: %s", outstr) } @@ -167,17 +159,11 @@ func TestVoltProfileShow(t *testing.T) { // (A, B) testutil.SuccessExit(t, out, err) - // (a, b, c, d) + // (a, b) outstr := string(out) if !strings.Contains(outstr, "name: default\n") { t.Errorf("Expected 'name: default' line, but got: %s", outstr) } - if !strings.Contains(outstr, "use vimrc: true\n") { - t.Errorf("Expected 'use vimrc: true' line, but got: %s", outstr) - } - if !strings.Contains(outstr, "use gvimrc: true\n") { - t.Errorf("Expected 'use gvimrc: true' line, but got: %s", outstr) - } if !strings.Contains(outstr, "repos path:\n") { t.Errorf("Expected 'repos path:' line, but got: %s", outstr) } @@ -194,7 +180,7 @@ func TestVoltProfileShow(t *testing.T) { // (!A, !B) testutil.FailExit(t, out, err) - // (!a, !b, !c, !d) + // (!a, !b) outstr := string(out) expected := "[ERROR] profile 'bar' does not exist" if strings.Trim(outstr, " \t\r\n") != expected { diff --git a/lockjson/lockjson.go b/lockjson/lockjson.go index c154525f..43ada1f8 100644 --- a/lockjson/lockjson.go +++ b/lockjson/lockjson.go @@ -44,8 +44,6 @@ type profReposPath []string type Profile struct { Name string `json:"name"` ReposPath profReposPath `json:"repos_path"` - UseVimrc bool `json:"use_vimrc"` - UseGvimrc bool `json:"use_gvimrc"` } const lockJSONVersion = 2 @@ -60,8 +58,6 @@ func initialLockJSON() *LockJSON { Profile{ Name: "default", ReposPath: make([]string, 0), - UseVimrc: true, - UseGvimrc: true, }, }, }