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

Feature/yaml config #1401

Merged
merged 12 commits into from
Dec 11, 2024
Merged
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
10 changes: 5 additions & 5 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ COVERAGE_DIR?=$(shell mktemp -d)
GOOS=$(shell go env GOHOSTOS)
GOARCH=$(shell go env GOHOSTARCH)

# Uncomment to update test outputs
# Uncomment to update system test gold files
# CAPTURE := "--capture"

help: ## Print this help
Expand Down Expand Up @@ -50,11 +50,11 @@ swagger-install:
echo "// @version $(VERSION)" >> docs/swagger.conf

azurite-start:
azurite & \
azurite -l /tmp/aptly-azurite & \
echo $$! > ~/.azurite.pid

azurite-stop:
kill `cat ~/.azurite.pid`
@kill `cat ~/.azurite.pid`

swagger: swagger-install
# Generate swagger docs
Expand Down Expand Up @@ -111,7 +111,7 @@ bench:
serve: prepare swagger-install ## Run development server (auto recompiling)
test -f $(BINPATH)/air || go install github.com/air-verse/[email protected]
cp debian/aptly.conf ~/.aptly.conf
sed -i /enableSwaggerEndpoint/s/false/true/ ~/.aptly.conf
sed -i /enable_swagger_endpoint/s/false/true/ ~/.aptly.conf
PATH=$(BINPATH):$$PATH air -build.pre_cmd 'swag init -q --markdownFiles docs --generalInfo docs/swagger.conf' -build.exclude_dir docs,system,debian,pgp/keyrings,pgp/test-bins,completion.d,man,deb/testdata,console,_man,systemd,obj-x86_64-linux-gnu -- api serve -listen 0.0.0.0:3142

dpkg: prepare swagger ## Build debian packages
Expand Down Expand Up @@ -210,7 +210,7 @@ man: ## Create man pages

clean: ## remove local build and module cache
# Clean all generated and build files
find .go/ -type d ! -perm -u=w -exec chmod u+w {} \;
test ! -e .go || find .go/ -type d ! -perm -u=w -exec chmod u+w {} \;
rm -rf .go/
rm -rf build/ obj-*-linux-gnu* tmp/
rm -f unit.out aptly.test VERSION docs/docs.go docs/swagger.json docs/swagger.yaml docs/swagger.conf
Expand Down
22 changes: 17 additions & 5 deletions cmd/config_show.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,29 @@
"fmt"

"github.com/smira/commander"
"gopkg.in/yaml.v3"
)

func aptlyConfigShow(_ *commander.Command, _ []string) error {
showYaml := context.Flags().Lookup("yaml").Value.Get().(bool)

config := context.Config()
prettyJSON, err := json.MarshalIndent(config, "", " ")

if err != nil {
return fmt.Errorf("unable to dump the config file: %s", err)
}
if showYaml {
yamlData, err := yaml.Marshal(&config)
if err != nil {
return fmt.Errorf("error marshaling to YAML: %s", err)
}

Check warning on line 20 in cmd/config_show.go

View check run for this annotation

Codecov / codecov/patch

cmd/config_show.go#L19-L20

Added lines #L19 - L20 were not covered by tests

fmt.Println(string(yamlData))
} else {
prettyJSON, err := json.MarshalIndent(config, "", " ")
if err != nil {
return fmt.Errorf("unable to dump the config file: %s", err)
}

Check warning on line 27 in cmd/config_show.go

View check run for this annotation

Codecov / codecov/patch

cmd/config_show.go#L26-L27

Added lines #L26 - L27 were not covered by tests

fmt.Println(string(prettyJSON))
fmt.Println(string(prettyJSON))
}

return nil
}
Expand All @@ -35,5 +46,6 @@

`,
}
cmd.Flag.Bool("yaml", false, "show yaml config")
return cmd
}
2 changes: 1 addition & 1 deletion context/context_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,6 @@ func (s *AptlyContextSuite) TestGetPublishedStorageBadFS(c *C) {
// storage never exists.
c.Assert(func() { s.context.GetPublishedStorage("filesystem:fuji") },
FatalErrorPanicMatches,
&FatalError{ReturnCode: 1, Message: fmt.Sprintf("error loading config file %s/.aptly.conf: EOF",
&FatalError{ReturnCode: 1, Message: fmt.Sprintf("error loading config file %s/.aptly.conf: invalid yaml (EOF) or json (EOF)",
os.Getenv("HOME"))})
}
Loading
Loading