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

Add more command flags #312

Merged
merged 5 commits into from
May 20, 2022
Merged
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
62 changes: 62 additions & 0 deletions cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,10 @@ var (
cpuProfile string
memProfile string
blockProfile string
onlineURL string
offlineURL string
startIndex int64
endIndex int64

// Config is the populated *configuration.Configuration from
// the configurationFile. If none is provided, this is set
Expand Down Expand Up @@ -217,13 +221,50 @@ default values.`,
"", // Default to skip validation
`Check that /network/options matches contents of file at this path`,
)

checkDataCmd.Flags().StringVar(
&onlineURL,
"online-url",
"",
"Override online node url in configuration file",
)

checkDataCmd.Flags().Int64Var(
&startIndex,
"start-block",
-1,
`start-block is the block height to start syncing from. This will override the start_index from configuration file`,
)

checkDataCmd.Flags().Int64Var(
&endIndex,
"end-block",
-1,
`End-block configures the syncer to stop once reaching a particular block height. This will override the index from configuration file`,
)

rootCmd.AddCommand(checkDataCmd)
checkConstructionCmd.Flags().StringVar(
&asserterConfigurationFile,
"asserter-configuration-file",
"", // Default to skip validation
`Check that /network/options matches contents of file at this path`,
)

checkConstructionCmd.Flags().StringVar(
&onlineURL,
"online-url",
"",
"Override online node url in configuration file",
)

checkConstructionCmd.Flags().StringVar(
&offlineURL,
"offline-url",
"",
"Override offline node url in configuration file",
)

rootCmd.AddCommand(checkConstructionCmd)

// View Commands
Expand Down Expand Up @@ -260,9 +301,30 @@ func initConfig() {
} else {
Config, err = configuration.LoadConfiguration(Context, configurationFile)
}

if err != nil {
log.Fatalf("%s: unable to load configuration", err.Error())
}

// Override node url in configuration file when it's explicitly set via CLI
if len(onlineURL) != 0 {
Config.OnlineURL = onlineURL
}
if len(offlineURL) != 0 {
Config.Construction.OfflineURL = offlineURL
}

// Override start and end syncing index in configuration file when it's explicitly set via CLI
if startIndex != -1 {
Config.Data.StartIndex = &startIndex
// Configures rosetta-cli to lookup the balance of newly seen accounts at the
// parent block before applying operations. Otherwise the balance will be 0.
Config.Data.InitialBalanceFetchDisabled = false
Copy link
Contributor

Choose a reason for hiding this comment

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

Please add comments why we toggle the flag.

}

if endIndex != -1 {
Config.Data.EndConditions.Index = &endIndex
}
}

func ensureDataDirectoryExists() {
Expand Down