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

Use CLI flags parser from Icinga Go Library #231

Merged
merged 1 commit into from
Jul 19, 2024
Merged

Conversation

yhabteab
Copy link
Member

@yhabteab yhabteab commented Jul 10, 2024

This PR replaces the manual parsing of the CLI flags with the CLI flags parser from our Icinga Go Library and cleans up the main function a bit. The flags are now parsed in daemon.ParseFlagsAndConfig function called from within main function and panics/exits when encountering unexpected inputs.

Requires

@cla-bot cla-bot bot added the cla/signed CLA is signed by all contributors of a PR label Jul 10, 2024
@yhabteab yhabteab added the enhancement New feature or request label Jul 10, 2024
@julianbrost
Copy link
Collaborator

The flags are now parsed during initialisation of the daemon package via the magical init() GO function and panics/exits when encountering unexpected inputs.

What is the benefit of doing this in init() instead of just calling from main() like it's done so far? The latter is where I'd expect that to happen, using init() just adds code that's running implicitly but is harder to find (you couldn't set a breakpoint in main() to debug it for example). IMHO it's just very strange if programs exit before even entering main().

@yhabteab
Copy link
Member Author

What is the benefit of doing this in init() instead of just calling from main() like it's done so far?

The only benefit I had from doing this was that I didn't have to explicitly make an Init call from within the main function, but now I'm going to change it though.

internal/daemon/config.go Outdated Show resolved Hide resolved
internal/daemon/config.go Outdated Show resolved Hide resolved
internal/daemon/config.go Outdated Show resolved Hide resolved
Copy link
Member

@oxzi oxzi left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Works as intended!

$ ./icinga-notifications --help
Usage:
  icinga-notifications [OPTIONS]

Application Options:
      --version  print version and exit
  -c, --config=  path to config file (default: /etc/icinga-notifications/config.yml)

Help Options:
  -h, --help     Show this help message

$ ./icinga-notifications --version
Icinga Notifications version: 0.0.0-gef68dc4-dirty

Build information:
  Go version: go1.22.5 (linux, amd64)
  Git commit: ef68dc48715792b1bf7d069aca9b4bdde9542c81 (modified)

System information:
  Platform: Red Star OS
  Platform version: 4.0

$ ./icinga-notifications
can't open YAML file /etc/icinga-notifications/config.yml: open /etc/icinga-notifications/config.yml: no such file or directory

$ ./icinga-notifications -c /dev/null
can't parse YAML file /dev/null: EOF

$ ./icinga-notifications --config /dev/null
can't parse YAML file /dev/null: EOF

internal/daemon/config.go Show resolved Hide resolved
@julianbrost julianbrost merged commit d7dab21 into main Jul 19, 2024
26 checks passed
@julianbrost julianbrost deleted the use-igl-cli-parser branch July 19, 2024 11:57
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
cla/signed CLA is signed by all contributors of a PR enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants