Skip to content
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

chore(deps-dev): bump the docs group across 1 directory with 3 updates #41

Closed
wants to merge 82 commits into from
Closed
Changes from 2 commits
Commits
Show all changes
82 commits
Select commit Hold shift + click to select a range
6272509
chore(deps): bump GoogleCloudPlatform/release-please-action from 3 to 4
dependabot[bot] Dec 25, 2023
f8f1977
Merge pull request #1 from asdf-vm/dependabot/github_actions/GoogleCl…
Stratus3D Dec 26, 2023
d69ed32
feat(golang-rewrite): initialize golang module
Stratus3D Dec 30, 2023
bc24a25
Merge pull request #5 from asdf-vm/tb/initialize-go-project
Stratus3D Dec 30, 2023
bb0c6ce
chore(deps): bump actions/cache from 3 to 4
dependabot[bot] Jan 22, 2024
c2e3f90
Merge pull request #7 from asdf-vm/dependabot/github_actions/actions/…
Stratus3D Jan 22, 2024
695103a
ci: update Fish version in test dependencies (#1705)
hyperupcall Jan 9, 2024
fa6415c
fix: avoid mention of `ASDF_NU_DIR` (#1660)
hyperupcall Jan 9, 2024
4b339f5
refactor: prefer grep `--quiet` over standard output redirection (#1655)
hyperupcall Jan 9, 2024
840fd72
fix: `plugin test` git-ref to use plugin repo default branch (#1694)
javiergarea Jan 9, 2024
5b96b0d
chore(deps): bump actions/setup-python from 4 to 5 (#1695)
dependabot[bot] Jan 9, 2024
92bf962
fix: list `asdf version` command under help.txt UTILS section (#1673)
aognio Jan 9, 2024
b000882
fix: warn if plugin does not support keeping downloads if configured …
hyperupcall Jan 9, 2024
e02e91c
fix: use universal scope for fish_user_paths (#1699)
bakotaco Jan 10, 2024
8ed0b59
docs: add Japanese translation (#1667)
RyoTagami Jan 10, 2024
6a553b5
perf: only create dirs if they do not already exist (#1566)
mattyo161 Jan 10, 2024
ec919c4
fix(nushell): Use `def --env` instead of `def-env` (#1681)
hyperupcall Jan 13, 2024
28a1c75
fix(fish): use PATH instead of fish_user_paths (#1709)
bakotaco Jan 18, 2024
c007696
test(fish): Improve test isolation (#1708)
hyperupcall Jan 19, 2024
9b3d7de
chore(master): release 0.14.0 (#1641)
github-actions[bot] Jan 19, 2024
1ebc038
fix: update GitHub workflows to work private asdf Go fork
Stratus3D Jan 27, 2024
60bc031
feat: add linting for Golang to GitHub lint workflow
Stratus3D Jan 27, 2024
428265d
feat: add Golang tests to GitHub test workflow
Stratus3D Jan 27, 2024
fdafb9f
Merge pull request #8 from asdf-vm/tb/github-workflow-setup
Stratus3D Feb 3, 2024
9a39f33
feat(golang-rewrite): setup goreleaser
Stratus3D Feb 3, 2024
e0637e9
feat(golang-rewrite): setup Golang release GitHub workflow
Stratus3D Feb 3, 2024
bbf8e89
fix(golang-rewrite): correct go build command in lint workflow
Stratus3D Feb 3, 2024
9a94976
Merge pull request #11 from asdf-vm/tb/golang-builds
Stratus3D Feb 3, 2024
405de52
fix(golang-rewrite): add missing goreleaser argument
Stratus3D Feb 3, 2024
4d29553
Merge pull request #12 from asdf-vm/tb/golang-build-fix
Stratus3D Feb 3, 2024
6818b51
fix(golang-rewrite): set dependencies between release-build jobs
Stratus3D Feb 3, 2024
e2e34e0
Merge pull request #13 from asdf-vm/tb/workflow-jobs-fix
Stratus3D Feb 3, 2024
f291f7a
fix(golang-rewrite): try to fix goreleaser
Stratus3D Feb 3, 2024
0d2bed8
Merge pull request #14 from asdf-vm/tb/attempt-to-fix-goreleaser
Stratus3D Feb 3, 2024
7c2a826
fix(golang-rewrite): try to get goreleaser action to generate snapsho…
Stratus3D Feb 4, 2024
9b65c41
Merge pull request #15 from asdf-vm/tb/attempt-to-fix-goreleaser-2
Stratus3D Feb 4, 2024
47fa2fe
fix(golang-rewrite): attempt to fix goreleaser GitHub workflow
Stratus3D Feb 8, 2024
c61489e
Merge pull request #19 from asdf-vm/tb/attempt-to-fix-goreleaser-3
Stratus3D Feb 8, 2024
59fb8aa
feat(golang-rewrite): run bats integration tests in golang
Stratus3D Feb 10, 2024
820089a
feat(golang-rewrite): build golang asdf for BATS integration tests
Stratus3D Feb 10, 2024
767aede
feat(golang-rewrite): set variables for bats integration tests
Stratus3D Feb 11, 2024
9a5e811
feat(golang-rewrite): make bats available for golang tests
Stratus3D Feb 11, 2024
b28327c
fix(golang-rewrite): fix dependencies script on linux
Stratus3D Feb 11, 2024
518fa5f
fix(golang-rewrite): comment out all BATS tests
Stratus3D Feb 11, 2024
1baab7d
Merge pull request #20 from asdf-vm/tb/bats-tests-golang
Stratus3D Feb 11, 2024
7d1f387
feat(golang-rewrite): add cobra library as dependency
Stratus3D Feb 12, 2024
b99795c
feat(golang-rewrite): add boilerplate for cobra CLI commands
Stratus3D Feb 13, 2024
de330df
Merge pull request #21 from asdf-vm/tb/cli-arg-parsing
Stratus3D Feb 13, 2024
48dc691
fix(golang-rewrite): update detect-changes logic for Golang tests
Stratus3D Feb 13, 2024
58f433f
Merge pull request #22 from asdf-vm/tb/workflow-fix
Stratus3D Feb 13, 2024
7097b97
feat(golang-rewrite): create settings and config structs for loading …
Stratus3D Feb 16, 2024
c00bebb
Merge pull request #23 from asdf-vm/tb/setup-config
Stratus3D Feb 19, 2024
fcea81e
chore(deps): bump actions/checkout from 3 to 4
dependabot[bot] Feb 19, 2024
edde355
Merge pull request #16 from asdf-vm/dependabot/github_actions/actions…
Stratus3D Feb 20, 2024
f0bbe8f
feat(golang-rewrite): add config methods
Stratus3D Feb 19, 2024
da9f842
Merge pull request #24 from asdf-vm/tb/config-api
Stratus3D Feb 21, 2024
0f5fba4
feat(golang-rewrite): add placeholders for plugin subcommands
Stratus3D Feb 22, 2024
e6f99c3
Merge pull request #25 from asdf-vm/tb/plugin-command-placeholders
Stratus3D Feb 23, 2024
752dd49
feat(golang-rewrite): PluginAdd function
Stratus3D Feb 23, 2024
dc0e048
Merge pull request #26 from asdf-vm/tb/plugin-add-command
Stratus3D Feb 28, 2024
dedfc84
feat(golang-rewrite): create pluginAddCommand function for plugin add…
Stratus3D Mar 1, 2024
66bf698
Merge pull request #28 from asdf-vm/tb/plugin-add-command-2
Stratus3D Mar 1, 2024
8260a42
feat(golang-rewrite): create plugin list command
Stratus3D Mar 1, 2024
2e58209
Merge pull request #29 from asdf-vm/tb/plugin-list-command
Stratus3D Mar 7, 2024
a03ead0
feat(golang-rewrite): create plugin remove command
Stratus3D Mar 7, 2024
5b4832a
Merge pull request #30 from asdf-vm/tb/plugin-remove-command
Stratus3D Mar 14, 2024
c07086c
feat(golang-rewrite): create Makefile
Stratus3D Mar 20, 2024
ee96257
Merge pull request #31 from asdf-vm/tb/add-makefile
Stratus3D Mar 21, 2024
22754eb
chore(golang-rewrite): Github workflow improvements
Stratus3D Mar 21, 2024
527c198
Merge pull request #32 from asdf-vm/tb/workflow-improvements
Stratus3D Mar 23, 2024
47c9a0e
chore(golang-rewrite): rename files for plugins and cmd packages
Stratus3D Mar 23, 2024
4cb5b79
chore(golang-rewrite): default settings refactor
Stratus3D Mar 23, 2024
f9b6a81
Merge pull request #33 from asdf-vm/tb/default-config-refactor
Stratus3D Mar 26, 2024
8bce1ab
chore(deps): bump amannn/action-semantic-pull-request
dependabot[bot] Apr 29, 2024
e4e7548
Merge pull request #37 from asdf-vm/dependabot/github_actions/amannn/…
Stratus3D Apr 29, 2024
c058421
feat(golang-rewrite): create plugins/git package to store plugin Git …
Stratus3D Apr 27, 2024
5663de9
Merge pull request #35 from asdf-vm/tb/plugin-git-package
Stratus3D Apr 30, 2024
c2267d1
chore(golang-rewrite): setup gofumpt
Stratus3D Apr 30, 2024
4b00c9d
Merge pull request #38 from asdf-vm/tb/setup-gofumpt
Stratus3D May 3, 2024
bcd893b
feat(golang-rewrite): create plugin update command
Stratus3D Apr 28, 2024
f262ffa
Merge pull request #36 from asdf-vm/tb/plugin-update-cmd
Stratus3D May 4, 2024
86378c7
chore(deps-dev): bump the docs group across 1 directory with 3 updates
dependabot[bot] Jun 1, 2024
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
153 changes: 123 additions & 30 deletions config.go
Original file line number Diff line number Diff line change
@@ -2,36 +2,65 @@ package main

import (
"context"
"strconv"
"strings"

"github.com/mitchellh/go-homedir"
"github.com/sethvargo/go-envconfig"
"gopkg.in/ini.v1"
)

// Not sure how best to represent this enum type
//type PluginRepositoryLastCheckDuration struct {
// Never bool
// Every int
//}
const LegacyVersionFileDefault = false
const AlwaysKeepDownloadDefault = false
const DisablePluginShortNameRepositoryDefault = false
const ForcePrependDefault = false
const DataDirDefault = "~/.asdf"
const ConfigFileDefault = "~/.asdfrc"
const DefaultToolVersionsFilenameDefault = ".tool-versions"

/* Struct to represent the remote plugin repo check duration (never or every N
* seconds). It's not clear to me how this should be represented in Golang so
* using a struct for maximum flexibility. */
type PluginRepoCheckDuration struct {
Never bool
Every int
}

var PluginRepoCheckDurationDefault = PluginRepoCheckDuration{Every: 60}

type Settings struct {
Loaded bool
LegacyVersionFile bool
// I don't think this setting should be supported in the Golang implementation
//UseReleaseCandidates bool
AlwaysKeepDownload bool
PluginRepositoryLastCheckDuration string
PluginRepositoryLastCheckDuration PluginRepoCheckDuration
DisablePluginShortNameRepository bool
}

type Config struct {
Home string
ConfigFile string `env:"ASDF_CONFIG_FILE"`
DefaultToolVersionsFilename string `env:"ASDF_DEFAULT_TOOL_VERSIONS_FILENAME"`
ConfigFile string `env:"ASDF_CONFIG_FILE, overwrite"`
DefaultToolVersionsFilename string `env:"ASDF_DEFAULT_TOOL_VERSIONS_FILENAME, overwrite"`
// Unclear if this value will be needed with the golang implementation.
//AsdfDir string
DataDir string `env:"ASDF_DATA_DIR"`
ForcePrepend bool `env:"ASDF_FORCE_PREPEND"`
DataDir string `env:"ASDF_DATA_DIR, overwrite"`
ForcePrepend bool `env:"ASDF_FORCE_PREPEND, overwrite"`
// Field that stores the settings struct if it is loaded
Settings Settings
}

func NewPluginRepoCheckDuration(checkDuration string) PluginRepoCheckDuration {
if strings.ToLower(checkDuration) == "never" {
return PluginRepoCheckDuration{Never: true}
} else {
every, err := strconv.Atoi(checkDuration)
if err != nil {
// if error parsing config use default value
return PluginRepoCheckDurationDefault
}
return PluginRepoCheckDuration{Every: every}
}
}

func LoadConfig() (Config, error) {
@@ -52,16 +81,90 @@ func LoadConfig() (Config, error) {
return config, nil
}

// Methods on the Config struct that allow it to load and cache values from the
// Settings struct, which is loaded from file on disk and therefor somewhat
// "expensive".
func (c *Config) LegacyVersionFile() (bool, error) {
err := c.loadSettings()

if err != nil {
return false, err
}

return c.Settings.LegacyVersionFile, nil
}

func (c *Config) AlwaysKeepDownload() (bool, error) {
err := c.loadSettings()

if err != nil {
return false, err
}

return c.Settings.AlwaysKeepDownload, nil
}

func (c *Config) PluginRepositoryLastCheckDuration() (PluginRepoCheckDuration, error) {
err := c.loadSettings()

if err != nil {
return NewPluginRepoCheckDuration(""), err
}

return c.Settings.PluginRepositoryLastCheckDuration, nil
}

func (c *Config) DisablePluginShortNameRepository() (bool, error) {
err := c.loadSettings()

if err != nil {
return false, err
}

return c.Settings.DisablePluginShortNameRepository, nil
}

func (c *Config) loadSettings() error {
if c.Settings.Loaded {
return nil
}

settings, err := loadSettings(c.ConfigFile)

if err != nil {
return err
}

c.Settings = settings

return nil
}

func loadConfigEnv() (Config, error) {
context := context.Background()
config := Config{}
dataDir, err := homedir.Expand(DataDirDefault)
if err != nil {
return Config{}, err
}

err := envconfig.Process(context, &config)
configFile, err := homedir.Expand(ConfigFileDefault)
if err != nil {
return Config{}, err
}

config := Config{
ForcePrepend: ForcePrependDefault,
DataDir: dataDir,
ConfigFile: configFile,
DefaultToolVersionsFilename: DefaultToolVersionsFilenameDefault,
}

context := context.Background()
err = envconfig.Process(context, &config)

return config, err
}

func LoadSettings(asdfrcPath string) (Settings, error) {
func loadSettings(asdfrcPath string) (Settings, error) {
// asdfrc is effectively formatted as ini
config, err := ini.Load(asdfrcPath)

@@ -70,17 +173,18 @@ func LoadSettings(asdfrcPath string) (Settings, error) {
}

mainConf := config.Section("")
checkDuration := stringToCheckDuration(mainConf.Key("plugin_repository_last_check_duration").String(), "60")
checkDuration := NewPluginRepoCheckDuration(mainConf.Key("plugin_repository_last_check_duration").String())

return Settings{
LegacyVersionFile: YesNoToBool(mainConf, "legacy_version_file", false),
AlwaysKeepDownload: YesNoToBool(mainConf, "use_release_candidates", false),
Loaded: true,
LegacyVersionFile: yesNoToBool(mainConf, "legacy_version_file", LegacyVersionFileDefault),
AlwaysKeepDownload: yesNoToBool(mainConf, "use_release_candidates", AlwaysKeepDownloadDefault),
PluginRepositoryLastCheckDuration: checkDuration,
DisablePluginShortNameRepository: YesNoToBool(mainConf, "disable_plugin_short_name_repository", false),
DisablePluginShortNameRepository: yesNoToBool(mainConf, "disable_plugin_short_name_repository", DisablePluginShortNameRepositoryDefault),
}, nil
}

func YesNoToBool(section *ini.Section, key string, defaultValue bool) bool {
func yesNoToBool(section *ini.Section, key string, defaultValue bool) bool {
yesOrNo := section.Key(key).String()
lcYesOrNo := strings.ToLower(yesOrNo)
if lcYesOrNo == "yes" {
@@ -92,14 +196,3 @@ func YesNoToBool(section *ini.Section, key string, defaultValue bool) bool {

return defaultValue
}

// Eventually this should return a custom type but I need to figure out how to
// represent the (never string, duration int) type. For now it just returns a
// string.
func stringToCheckDuration(checkDuration string, defaultValue string) string {
if checkDuration != "" {
return checkDuration
}

return defaultValue
}
52 changes: 47 additions & 5 deletions config_test.go
Original file line number Diff line number Diff line change
@@ -22,37 +22,79 @@ func TestLoadConfigEnv(t *testing.T) {

func TestLoadSettings(t *testing.T) {
t.Run("When given invalid path returns error", func(t *testing.T) {
_, err := LoadSettings("./foobar")
settings, err := loadSettings("./foobar")

if err == nil {
t.Fatal("Didn't get an error")
}

if settings.Loaded {
t.Fatal("Didn't expect settings to be loaded")
}
})

t.Run("When given path to populated asdfrc returns populated settings struct", func(t *testing.T) {
settings, err := LoadSettings("testdata/asdfrc")
settings, err := loadSettings("testdata/asdfrc")

refuteError(t, err)

assert(t, settings.Loaded, "Expected Loaded field to be set to true")
assert(t, settings.LegacyVersionFile == true, "LegacyVersionFile field has wrong value")
assert(t, settings.AlwaysKeepDownload == true, "AlwaysKeepDownload field has wrong value")
assert(t, settings.PluginRepositoryLastCheckDuration == "never", "PluginRepositoryLastCheckDuration field has wrong value")
assert(t, settings.PluginRepositoryLastCheckDuration.Never, "PluginRepositoryLastCheckDuration field has wrong value")
assert(t, settings.PluginRepositoryLastCheckDuration.Every == 0, "PluginRepositoryLastCheckDuration field has wrong value")
assert(t, settings.DisablePluginShortNameRepository == true, "DisablePluginShortNameRepository field has wrong value")
})

t.Run("When given path to empty file returns settings struct with defaults", func(t *testing.T) {
settings, err := LoadSettings("testdata/empty-asdfrc")
settings, err := loadSettings("testdata/empty-asdfrc")

refuteError(t, err)

assert(t, settings.LegacyVersionFile == false, "LegacyVersionFile field has wrong value")
assert(t, settings.AlwaysKeepDownload == false, "AlwaysKeepDownload field has wrong value")
assert(t, settings.PluginRepositoryLastCheckDuration == "60", "PluginRepositoryLastCheckDuration field has wrong value")
assert(t, settings.PluginRepositoryLastCheckDuration.Never == false, "PluginRepositoryLastCheckDuration field has wrong value")
assert(t, settings.PluginRepositoryLastCheckDuration.Every == 60, "PluginRepositoryLastCheckDuration field has wrong value")
assert(t, settings.DisablePluginShortNameRepository == false, "DisablePluginShortNameRepository field has wrong value")
})
}

func TestConfigMethods(t *testing.T) {
// Set the asdf config file location to the test file
t.Setenv("ASDF_CONFIG_FILE", "testdata/asdfrc")

config, err := LoadConfig()
assert(t, err == nil, "Returned error when building config")

t.Run("Returns LegacyVersionFile from asdfrc file", func(t *testing.T) {
legacyFile, err := config.LegacyVersionFile()
assert(t, err == nil, "Returned error when loading settings")
assert(t, legacyFile == true, "Expected LegacyVersionFile to be set")
})

t.Run("Returns AlwaysKeepDownload from asdfrc file", func(t *testing.T) {
alwaysKeepDownload, err := config.AlwaysKeepDownload()
assert(t, err == nil, "Returned error when loading settings")
assert(t, alwaysKeepDownload == true, "Expected AlwaysKeepDownload to be set")
})

t.Run("Returns PluginRepositoryLastCheckDuration from asdfrc file", func(t *testing.T) {
checkDuration, err := config.PluginRepositoryLastCheckDuration()
assert(t, err == nil, "Returned error when loading settings")
assert(t, checkDuration.Never == true, "Expected PluginRepositoryLastCheckDuration to be set")
assert(t, checkDuration.Every == 0, "Expected PluginRepositoryLastCheckDuration to be set")
})

t.Run("Returns DisablePluginShortNameRepository from asdfrc file", func(t *testing.T) {
DisablePluginShortNameRepository, err := config.DisablePluginShortNameRepository()
assert(t, err == nil, "Returned error when loading settings")
assert(t, DisablePluginShortNameRepository == true, "Expected DisablePluginShortNameRepository to be set")
})
}

func assert(t *testing.T, expr bool, message string) {
t.Helper()

if !expr {
t.Error(message)
}

Unchanged files with check annotations Beta

//})
}
func run_bats_file(t *testing.T, dir, filename string) {

Check failure on line 129 in main_test.go

GitHub Actions / asdf-golang

func run_bats_file is unused (U1000)
t.Helper()
cmd := exec.Command("bats", "--verbose-run", fmt.Sprintf("test/%s", filename))