Skip to content

feat: rename set command's --parent flag to --parents #2058

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 12 additions & 12 deletions asdf.elv
Original file line number Diff line number Diff line change
Expand Up @@ -150,29 +150,29 @@ fn arg-completer {|@argz|
# asdf list <name> [<version>]
ls-installed-versions $argz[-1]
} elif (match $argz 'local') {
# asdf local <name> [-p|--parent]
# asdf local <name> [-p|--parents]
asdf plugin-list
put '-p'
put '--parent'
} elif (match $argz 'local' '(-p|(--parent))') {
# asdf local <name> [-p|--parent] <version>
put '--parents'
} elif (match $argz 'local' '(-p|(--parents))') {
# asdf local <name> [-p|--parents] <version>
asdf plugin-list
} elif (match $argz 'local' '.*') {
# asdf local <name> [-p|--parent]
# asdf local <name> [-p|--parents]
# asdf local <name> <version>
ls-installed-versions $argz[-1]
put '-p'
put '--parent'
} elif (match $argz 'local' '(-p|(--parent))' '.*') {
# asdf local [-p|--parent] <name> <version>
put '--parents'
} elif (match $argz 'local' '(-p|(--parents))' '.*') {
# asdf local [-p|--parents] <name> <version>
ls-installed-versions $argz[-1]
} elif (match $argz 'local' '.*' '(-p|(--parent))') {
# asdf local <name> [-p|--parent] <version>
} elif (match $argz 'local' '.*' '(-p|(--parents))') {
# asdf local <name> [-p|--parents] <version>
ls-installed-versions $argz[-2]
} elif (match $argz 'local' '.*' '.*') {
# asdf local <name> <version> [-p|--parent]
# asdf local <name> <version> [-p|--parents]
put '-p'
put '--parent'
put '--parents'
} elif (or (match $argz 'plugin-add') (match $argz 'plugin' 'add')) {
# asdf plugin add <name>
asdf plugin-list-all | each {|line|
Expand Down
2 changes: 1 addition & 1 deletion docs/guide/upgrading-to-v0-16.md
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ terminology was wrong and also misleading. asdf doesn't actually support
current directory specifying a different version. This was confusing to users.
The new `asdf set` behaves the same as `asdf local` by default, but also has
flags for setting versions in the user's home directory (`--home`) and in an
existing `.tool-versions` file in one of the parent directories (`--parent`).
existing `.tool-versions` file in one of the parent directories (`--parents`).
This new interface will hopefully convey a better understanding of how asdf
resolves versions and provide equivalent functionality.

Expand Down
2 changes: 1 addition & 1 deletion docs/ja-jp/guide/upgrading-to-v0-16.md
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ asdfバージョン0.15.0およびそれ以前では、特定のコマンドの

### `asdf global` と `asdf local` コマンドが `asdf set` に変更されました

`asdf global` と `asdf local` は削除されました。「グローバル」と「ローカル」という用語は誤りで、誤解を招く恐れがありました。asdf は、実際にはあらゆる場所に適用される「グローバル」バージョンをサポートしていません。`asdf global`で指定したバージョンは、カレントディレクトリにある `.tool-versions` ファイルで簡単に上書きすることができました。これはユーザーを混乱させていました。 新しい`asdf set`はデフォルトでは`asdf local`と同じように動作しますが、ユーザーのホームディレクトリ (`--home`) や親ディレクトリ (`--parent`) にある既存の `.tool-versions` ファイルにバージョンを設定するためのフラグも用意されています。 この新しいインターフェイスは、asdfがどのようにバージョンを解決するかをよりよく理解し、同等の機能を提供することを期待しています。
`asdf global` と `asdf local` は削除されました。「グローバル」と「ローカル」という用語は誤りで、誤解を招く恐れがありました。asdf は、実際にはあらゆる場所に適用される「グローバル」バージョンをサポートしていません。`asdf global`で指定したバージョンは、カレントディレクトリにある `.tool-versions` ファイルで簡単に上書きすることができました。これはユーザーを混乱させていました。 新しい`asdf set`はデフォルトでは`asdf local`と同じように動作しますが、ユーザーのホームディレクトリ (`--home`) や親ディレクトリ (`--parents`) にある既存の `.tool-versions` ファイルにバージョンを設定するためのフラグも用意されています。 この新しいインターフェイスは、asdfがどのようにバージョンを解決するかをよりよく理解し、同等の機能を提供することを期待しています。

### `asdf update`コマンドが削除されました

Expand Down
2 changes: 1 addition & 1 deletion docs/ja-jp/manage/versions.md
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ asdf set <name> latest[:<version>]

`u` または `--home`フラグをつけて`asdf set`を実行すると、`$HOME`ディレクトリの`.tool-versions`ファイルにバージョンを書き込みます。ファイルが存在しない場合は作成されます。

`p`または `--parent`フラグをつけて`asdf set`を実行すると、カレントディレクトリから親ディレクトリを探索し、最初に見つかった`.tool-versions` ファイルにバージョンを書き込みます。
`p`または `--parents`フラグをつけて`asdf set`を実行すると、カレントディレクトリから親ディレクトリを探索し、最初に見つかった`.tool-versions` ファイルにバージョンを書き込みます。

#### 環境変数で管理する

Expand Down
2 changes: 1 addition & 1 deletion docs/manage/versions.md
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ just doing `echo "<tool> <version>" > .tool-versions`.
With the `-u`/`--home` flag `asdf set` writes to the `.tool-versions` file in
your `$HOME` directory, creating the file if it does not exist.

With the `-p`/`--parent` flag `asdf set` finds a `.tool-versions` file in the
With the `-p`/`--parents` flag `asdf set` finds a `.tool-versions` file in the
closest parent directory of the current directory.

#### Via Environment Variable
Expand Down
19 changes: 16 additions & 3 deletions internal/cli/cli.go
Original file line number Diff line number Diff line change
Expand Up @@ -275,16 +275,29 @@ func Execute(version string) {
Usage: "The version should be set in the current users home directory",
},
&cli.BoolFlag{
Name: "parent",
Name: "parents",
Aliases: []string{"p"},
Usage: "The version should be set in the closest existing .tool-versions file in a parent directory",
Usage: "The version should be set in the closest existing .tool-versions file in a parent directory.",
},
&cli.BoolFlag{
Name: "parent",
Hidden: false,
Usage: "Has been renamed to --parents. See above.",
},
},
Action: func(cCtx *cli.Context) error {
args := cCtx.Args().Slice()
home := cCtx.Bool("home")
parents := cCtx.Bool("parents")
parent := cCtx.Bool("parent")
return set.Main(os.Stdout, os.Stderr, args, home, parent, func() (string, error) {

if parent {
const msg = "Warning: set --parent has been renamed to --parents. Please use --parents instead."
logger.Println(msg)
}


return set.Main(os.Stdout, os.Stderr, args, home, parents || parent, func() (string, error) {
return os.UserHomeDir()
})
},
Expand Down
16 changes: 8 additions & 8 deletions internal/cli/set/set.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import (
)

// Main function is the entrypoint for the 'asdf set' command
func Main(_ io.Writer, stderr io.Writer, args []string, home bool, parent bool, homeFunc func() (string, error)) error {
func Main(_ io.Writer, stderr io.Writer, args []string, home bool, parents bool, homeFunc func() (string, error)) error {
if len(args) < 1 {
return printError(stderr, "tool and version must be provided as arguments")
}
Expand All @@ -24,8 +24,8 @@ func Main(_ io.Writer, stderr io.Writer, args []string, home bool, parent bool,
return printError(stderr, "version must be provided as an argument")
}

if home && parent {
return printError(stderr, "home and parent flags cannot both be specified; must be one location or the other")
if home && parents {
return printError(stderr, "home and parents flags cannot both be specified; must be one location or the other")
}

conf, err := config.LoadConfig()
Expand Down Expand Up @@ -70,11 +70,11 @@ func Main(_ io.Writer, stderr io.Writer, args []string, home bool, parent bool,
return printError(stderr, fmt.Sprintf("unable to get current directory: %s", err))
}

if parent {
// locate file in parent dir and update it
path, found := findVersionFileInParentDir(conf, currentDir)
if parents {
// locate file in parents dir and update it
path, found := findVersionFileInParentDirs(conf, currentDir)
if !found {
return printError(stderr, fmt.Sprintf("No %s version file found in parent directory", conf.DefaultToolVersionsFilename))
return printError(stderr, fmt.Sprintf("No %s version file found in parent directories", conf.DefaultToolVersionsFilename))
}

err = toolversions.WriteToolVersionsToFile(path, []toolversions.ToolVersions{tv})
Expand All @@ -94,7 +94,7 @@ func printError(stderr io.Writer, msg string) error {
return errors.New(msg)
}

func findVersionFileInParentDir(conf config.Config, directory string) (string, bool) {
func findVersionFileInParentDirs(conf config.Config, directory string) (string, bool) {
directory = filepath.Dir(directory)

for {
Expand Down
8 changes: 4 additions & 4 deletions internal/cli/set/set_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,13 +32,13 @@ func TestAll(t *testing.T) {
assert.Equal(t, stderr.String(), "version must be provided as an argument")
})

t.Run("prints error when both --parent and --home flags are set", func(t *testing.T) {
t.Run("prints error when both --parents and --home flags are set", func(t *testing.T) {
stdout, stderr := buildOutputs()
err := Main(&stdout, &stderr, []string{"lua", "5.2.3"}, true, true, homeFunc)

assert.Error(t, err, "home and parent flags cannot both be specified; must be one location or the other")
assert.Error(t, err, "home and parents flags cannot both be specified; must be one location or the other")
assert.Equal(t, stdout.String(), "")
assert.Equal(t, stderr.String(), "home and parent flags cannot both be specified; must be one location or the other")
assert.Equal(t, stderr.String(), "home and parents flags cannot both be specified; must be one location or the other")
})

t.Run("sets version in current directory when no flags provided", func(t *testing.T) {
Expand All @@ -58,7 +58,7 @@ func TestAll(t *testing.T) {
assert.Equal(t, "lua 5.2.3\n", string(bytes))
})

t.Run("sets version in parent directory when --parent flag provided", func(t *testing.T) {
t.Run("sets version in parents directory when --parents flag provided", func(t *testing.T) {
stdout, stderr := buildOutputs()
dir := t.TempDir()
subdir := filepath.Join(dir, "subdir")
Expand Down
24 changes: 12 additions & 12 deletions internal/completions/asdf.elvish
Original file line number Diff line number Diff line change
Expand Up @@ -55,29 +55,29 @@ fn arg-completer {|@argz|
# asdf list <name> [<version>]
ls-installed-versions $argz[-1]
} elif (match $argz 'local') {
# asdf local <name> [-p|--parent]
# asdf local <name> [-p|--parents]
asdf plugin-list
put '-p'
put '--parent'
} elif (match $argz 'local' '(-p|(--parent))') {
# asdf local <name> [-p|--parent] <version>
put '--parents'
} elif (match $argz 'local' '(-p|(--parents))') {
# asdf local <name> [-p|--parents] <version>
asdf plugin-list
} elif (match $argz 'local' '.*') {
# asdf local <name> [-p|--parent]
# asdf local <name> [-p|--parents]
# asdf local <name> <version>
ls-installed-versions $argz[-1]
put '-p'
put '--parent'
} elif (match $argz 'local' '(-p|(--parent))' '.*') {
# asdf local [-p|--parent] <name> <version>
put '--parents'
} elif (match $argz 'local' '(-p|(--parents))' '.*') {
# asdf local [-p|--parents] <name> <version>
ls-installed-versions $argz[-1]
} elif (match $argz 'local' '.*' '(-p|(--parent))') {
# asdf local <name> [-p|--parent] <version>
} elif (match $argz 'local' '.*' '(-p|(--parents))') {
# asdf local <name> [-p|--parents] <version>
ls-installed-versions $argz[-2]
} elif (match $argz 'local' '.*' '.*') {
# asdf local <name> <version> [-p|--parent]
# asdf local <name> <version> [-p|--parents]
put '-p'
put '--parent'
put '--parents'
} elif (or (match $argz 'plugin-add') (match $argz 'plugin' 'add')) {
# asdf plugin add <name>
asdf plugin-list-all | each {|line|
Expand Down
2 changes: 1 addition & 1 deletion internal/completions/asdf.fish
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ complete -f -c asdf -n '__fish_asdf_using_command set; and test (count (commandl

# set commands
complete -f -c asdf -n '__fish_asdf_using_command set' -l home -d "Set version in home directory"
complete -f -c asdf -n '__fish_asdf_using_command set' -l parent -d "Set version in parent directory"
complete -f -c asdf -n '__fish_asdf_using_command set' -l parents -d "Set version in closest parent directory"

# misc
complete -f -c asdf -n __fish_asdf_needs_command -l help -d "Displays help"
Expand Down
4 changes: 2 additions & 2 deletions internal/help/help.txt
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,8 @@ asdf list <name> [version] List installed versions of a package and
asdf list all <name> [<version>] List all versions of a package and
optionally filter the returned versions
asdf set [-u] [-p] <name> <versions...> Set a tool version in a .tool-version in
the current directory, or a parent
directory.
the current directory, or the closest
parent directory.
asdf uninstall <name> <version> Remove a specific version of a package
asdf where <name> [<version>] Display install path for an installed
or current version
Expand Down
2 changes: 1 addition & 1 deletion internal/resolve/resolve_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ func TestVersion(t *testing.T) {
assert.Equal(t, toolVersion.Versions, []string{"2.3.4"})
})

t.Run("returns single version from .tool-versions file in parent directory", func(t *testing.T) {
t.Run("returns single version from .tool-versions file in closest parent directory", func(t *testing.T) {
// write a version file
data := []byte(fmt.Sprintf("%s 1.2.3", testPluginName))
err = os.WriteFile(filepath.Join(currentDir, ".tool-versions"), data, 0o666)
Expand Down
8 changes: 4 additions & 4 deletions lib/functions/versions.bash
Original file line number Diff line number Diff line change
Expand Up @@ -214,13 +214,13 @@ latest_all() {
}

local_command() {
local parent=false
local parents=false
local positional=()

while [[ $# -gt 0 ]]; do
case $1 in
-p | --parent)
parent="true"
-p | --parents)
parents="true"
shift # past value
;;
*)
Expand All @@ -232,7 +232,7 @@ local_command() {

set -- "${positional[@]}" # restore positional parameters

if [ $parent = true ]; then
if [ $parents = true ]; then
version_command local-tree "$@"
else
version_command local "$@"
Expand Down
3 changes: 3 additions & 0 deletions scripts/checkstyle.py
Original file line number Diff line number Diff line change
Expand Up @@ -254,6 +254,9 @@ def main():
for file in Path.cwd().glob('**/*'):
if '.git' in str(file.absolute()):
continue

if file.name == '.DS_Store':
continue

if file.is_file():
lintfile(file, rules, options)
Expand Down
2 changes: 2 additions & 0 deletions scripts/lint.bash
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,8 @@ run_custom_python_stylecheck() {
printf "%s\n" "[WARNING] python3 not found. Skipping Custom Python Script."
else
print.info "Checking files with Custom Python Script."
print.info "${flag}"
print.info "${0%/*}/checkstyle.py"
"${0%/*}/checkstyle.py" "${flag}"
fi

Expand Down
2 changes: 1 addition & 1 deletion test/install_command.bats
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,7 @@ EOM
[ ! -f "$ASDF_DIR/installs/other-dummy/2.0.0/version" ]
}

@test "install_command without arguments uses a parent directory .tool-versions file if present" {
@test "install_command without arguments uses the closest parent directory .tool-versions file if present" {
# asdf lib needed to run generated shims
cp -rf "$BATS_TEST_DIRNAME"/../{bin,lib} "$ASDF_DIR/"

Expand Down
2 changes: 1 addition & 1 deletion test/utils.bats
Original file line number Diff line number Diff line change
Expand Up @@ -338,7 +338,7 @@ teardown() {
[ "$output" = "$PROJECT_DIR/.tool-versions" ]
}

@test "find_tool_versions will find a .tool-versions path if it exists in parent directory" {
@test "find_tool_versions will find a .tool-versions path if it exists in any parent directory" {
echo "dummy 0.1.0" >"$PROJECT_DIR/.tool-versions"
mkdir -p "$PROJECT_DIR/child"
cd "$PROJECT_DIR"/child
Expand Down
12 changes: 6 additions & 6 deletions test/version_commands.bats
Original file line number Diff line number Diff line change
Expand Up @@ -156,41 +156,41 @@ teardown() {
[ "$(cat "$PROJECT_DIR/.tool-versions")" = "dummy path:$PROJECT_DIR/local" ]
}

@test "local -p/--parent should set should emit an error when called with incorrect arity" {
@test "local -p/--parents should set should emit an error when called with incorrect arity" {
run asdf local -p "dummy"
[ "$status" -eq 1 ]
[ "$output" = "Usage: asdf local <name> <version>" ]
}

@test "local -p/--parent should emit an error when plugin does not exist" {
@test "local -p/--parents should emit an error when plugin does not exist" {
run asdf local -p "inexistent" "1.0.0"
[ "$status" -eq 1 ]
[ "$output" = "No such plugin: inexistent" ]
}

@test "local -p/--parent should emit an error when plugin version does not exist" {
@test "local -p/--parents should emit an error when plugin version does not exist" {
run asdf local -p "dummy" "0.0.1"
[ "$status" -eq 1 ]
[ "$output" = "version 0.0.1 is not installed for dummy" ]
}

@test "local -p/--parent should allow multiple versions" {
@test "local -p/--parents should allow multiple versions" {
cd "$CHILD_DIR"
touch "$PROJECT_DIR/.tool-versions"
run asdf local -p "dummy" "1.1.0" "1.0.0"
[ "$status" -eq 0 ]
[ "$(cat "$PROJECT_DIR/.tool-versions")" = "dummy 1.1.0 1.0.0" ]
}

@test "local -p/--parent should overwrite the existing version if it's set" {
@test "local -p/--parents should overwrite the existing version if it's set" {
cd "$CHILD_DIR"
echo 'dummy 1.0.0' >>"$PROJECT_DIR/.tool-versions"
run asdf local -p "dummy" "1.1.0"
[ "$status" -eq 0 ]
[ "$(cat "$PROJECT_DIR/.tool-versions")" = "dummy 1.1.0" ]
}

@test "local -p/--parent should set the version if it's unset" {
@test "local -p/--parents should set the version if it's unset" {
cd "$CHILD_DIR"
touch "$PROJECT_DIR/.tool-versions"
run asdf local -p "dummy" "1.1.0"
Expand Down