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

feat: improve toml formatting #758

Merged
merged 1 commit into from
Jun 6, 2024
Merged

feat: improve toml formatting #758

merged 1 commit into from
Jun 6, 2024

Conversation

phm07
Copy link
Contributor

@phm07 phm07 commented May 21, 2024

This PR changes the TOML library from pelletier/go-toml/v2 to BurntSushi/toml. This improves the formatting of TOML files by using indents and also uses time.Duration's string values instead of writing nanoseconds into the config file.

Config format example

Before:

active_context = 'test_context'

[preferences]
debug = true
poll_interval = 1234000000

[[contexts]]
name = 'test_context'
token = 'super secret token'

[contexts.preferences]
array_option = ['1', '2', '3']
endpoint = 'https://test-endpoint.com'
quiet = true

[contexts.preferences.nested]
array_option = ['1', '2', '3']

[[contexts]]
name = 'other_context'
token = 'another super secret token'

[contexts.preferences]
poll_interval = 1234000000

After:

active_context = "test_context"

[preferences]
  debug = true
  poll_interval = "1.234s"

[[contexts]]
  name = "test_context"
  token = "super secret token"
  [contexts.preferences]
    array_option = ["1", "2", "3"]
    endpoint = "https://test-endpoint.com"
    quiet = true
    [contexts.preferences.nested]
      array_option = ["1", "2", "3"]

[[contexts]]
  name = "other_context"
  token = "another super secret token"
  [contexts.preferences]
    poll_interval = "1.234s"

Contexts are now grouped together instead of there being exactly one newline between every section, regardless of being in another context or not. Also, nested sections are now indented, which helps with understanding the structure.

Binary size

Before:

➜  cli git:(21e342b) GOARCH=amd64 GOOS=linux go build -o hcloud cmd/hcloud/main.go
➜  cli git:(21e342b) wc -c hcloud                                                 
 20606086 hcloud

After:

➜  cli git:(d336765) GOARCH=amd64 GOOS=linux go build -o hcloud cmd/hcloud/main.go
➜  cli git:(d336765) wc -c hcloud 
 20890490 hcloud

The binary size increases by ~1.4%, which is negligible.

Copy link

codecov bot commented May 21, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 59.32%. Comparing base (d1c6678) to head (aec51fb).

Additional details and impacted files
@@           Coverage Diff           @@
##             main     #758   +/-   ##
=======================================
  Coverage   59.32%   59.32%           
=======================================
  Files         203      203           
  Lines        7460     7460           
=======================================
  Hits         4426     4426           
  Misses       2400     2400           
  Partials      634      634           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@phm07 phm07 marked this pull request as ready for review June 6, 2024 14:54
@phm07 phm07 requested a review from a team as a code owner June 6, 2024 14:54
@phm07 phm07 merged commit eacb7dd into main Jun 6, 2024
5 checks passed
@phm07 phm07 deleted the switch-toml-lib branch June 6, 2024 15:01
phm07 pushed a commit that referenced this pull request Jun 20, 2024
🤖 I have created a release *beep* *boop*
---


##
[1.44.0](v1.43.1...v1.44.0)
(2024-06-20)


### Features

* delete multiple resources in parallel
([#761](#761))
([f2fb321](f2fb321))
* improve toml formatting
([#758](#758))
([eacb7dd](eacb7dd))
* **load-balancer:** allow specifying health check options in
add-service ([#743](#743))
([2cd08b2](2cd08b2)),
closes [#742](#742)
* new action waiting progress
([#749](#749))
([9e30f3f](9e30f3f))
* new configuration system, config subcommand
([#736](#736))
([d1c6678](d1c6678))
* **server-type:** add deprecated column to list command
([#780](#780))
([906f864](906f864))
* **server:** add default-ssh-keys option
([#759](#759))
([9b34d26](9b34d26))


### Bug Fixes

* **firewall:** 'create --rules-file' not working with outbound rules
([#752](#752))
([2f2be32](2f2be32)),
closes [#750](#750)
* network list server count format
([#783](#783))
([f69d261](f69d261))
* track progress if the terminal width allows it
([#768](#768))
([069fffe](069fffe)),
closes [#767](#767)

---
This PR was generated with [Release
Please](https://github.com/googleapis/release-please). See
[documentation](https://github.com/googleapis/release-please#release-please).
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants