-
Notifications
You must be signed in to change notification settings - Fork 13
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
Support configuration file for export command #55
Open
WordlessEcho
wants to merge
18
commits into
uyuni-project:main
Choose a base branch
from
WordlessEcho:config-file
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 6 commits
Commits
Show all changes
18 commits
Select commit
Hold shift + click to select a range
a8c2a73
Add configuration file support of export command
WordlessEcho fee8035
Fix default value detection
WordlessEcho e3be37c
Fix path of configuration file
WordlessEcho d3cf324
Move setOptionsByConfig to separate file
WordlessEcho 8f217cf
Read outputDir from options
WordlessEcho 5be4e6d
Do not change ServerConfig in exportConfigDumper
WordlessEcho e192247
Use viper to read configurations
WordlessEcho 9e430b1
Remove unused implements of configuration reader
WordlessEcho 040ef0c
Rename `channel-with-children`
WordlessEcho f497fb0
Add documents for export configurations
WordlessEcho 56d7f54
Fix packagesOnlyAfter to read config
WordlessEcho 9926133
Fix orgLimit
WordlessEcho 94c9dd5
Move `config` to root as global flag
WordlessEcho 65890b8
Support configuration file for import
WordlessEcho 002629d
Fatal instead of Warn when failed to BindPFlags()
WordlessEcho ed7e26d
Update documents of configuration file
WordlessEcho 96a3f19
Edit error message to avoid confusion of config
WordlessEcho a5eaa14
Trim empty lines
WordlessEcho File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
package entityDumper | ||
|
||
import ( | ||
"encoding/json" | ||
"github.com/rs/zerolog/log" | ||
"github.com/uyuni-project/inter-server-sync/utils" | ||
"io" | ||
"os" | ||
) | ||
|
||
func SetOptionsByConfig(configPath string, options *DumperOptions) { | ||
var config ExportConfig | ||
|
||
if configPath == "" { | ||
return | ||
} | ||
|
||
configFile, err := os.Open(utils.GetAbsPath(configPath)) | ||
if err != nil { | ||
log.Panic().Err(err).Msg("failed to open config file") | ||
} | ||
defer func(configFile *os.File) { | ||
err := configFile.Close() | ||
if err != nil { | ||
log.Warn().Err(err).Msg("failed to close config file") | ||
} | ||
}(configFile) | ||
|
||
configBytes, err := io.ReadAll(configFile) | ||
if err != nil { | ||
log.Panic().Err(err).Msg("failed to read config file") | ||
} | ||
|
||
if err = json.Unmarshal(configBytes, &config); err != nil { | ||
log.Panic().Err(err).Msg("failed to unmarshal config file") | ||
} | ||
|
||
// ServerConfig is set by cmd/root.go | ||
// Should we change it anyway? | ||
//if options.ServerConfig == "/etc/rhn/rhn.conf" && config.ServerConfig != "" { | ||
// options.ServerConfig = config.ServerConfig | ||
//} | ||
|
||
if options.OutputFolder == "." && config.OutputDir != "" { | ||
options.OutputFolder = config.OutputDir | ||
} | ||
|
||
if len(options.ChannelLabels) == 0 { | ||
options.ChannelLabels = config.Channels | ||
} | ||
|
||
if len(options.ChannelWithChildrenLabels) == 0 { | ||
options.ChannelWithChildrenLabels = config.ChannelWithChildren | ||
} | ||
|
||
if len(options.ConfigLabels) == 0 { | ||
options.ConfigLabels = config.ConfigChannels | ||
} | ||
|
||
if config.MetadataOnly { | ||
options.MetadataOnly = config.MetadataOnly | ||
} | ||
|
||
if options.StartingDate == "" { | ||
options.StartingDate = config.StartingDate | ||
} | ||
|
||
if len(options.Orgs) == 0 { | ||
options.Orgs = config.Orgs | ||
} | ||
|
||
if config.IncludeImages { | ||
options.OSImages = config.IncludeImages | ||
} | ||
|
||
if config.IncludeContainers { | ||
options.Containers = config.IncludeContainers | ||
} | ||
WordlessEcho marked this conversation as resolved.
Show resolved
Hide resolved
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That's a nice approach. I'd like it to be a bit more explicit on the user interface level, that we for example can either provide a config or specify it as a set of args. This way we could probably not mix them together with the options. What do you think?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@avshiliaev Sorry. I didn't catch your point... Can you give me some examples?
Or I guess that you hope the
--config
could be global flag as same as--serverConfig
?