-
Notifications
You must be signed in to change notification settings - Fork 35
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: improve design of shared and private CLI options (#864)
Signed-off-by: Tsvetan Dimitrov <[email protected]> Co-authored-by: Fabio Di Fabio <[email protected]>
- Loading branch information
1 parent
ec0cb14
commit 89ddb14
Showing
15 changed files
with
247 additions
and
178 deletions.
There are no files selected for viewing
83 changes: 83 additions & 0 deletions
83
arithmetization/src/main/java/net/consensys/linea/plugins/AbstractLineaOptionsPlugin.java
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,83 @@ | ||
/* | ||
* Copyright Consensys Software Inc. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with | ||
* the License. You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on | ||
* an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the | ||
* specific language governing permissions and limitations under the License. | ||
* | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
package net.consensys.linea.plugins; | ||
|
||
import java.util.HashMap; | ||
import java.util.Map; | ||
|
||
import lombok.extern.slf4j.Slf4j; | ||
import org.hyperledger.besu.plugin.BesuContext; | ||
import org.hyperledger.besu.plugin.BesuPlugin; | ||
import org.hyperledger.besu.plugin.services.PicoCLIOptions; | ||
|
||
/** | ||
* In this class we put CLI options that are private to plugins in this repo. | ||
* | ||
* <p>For the moment is just a placeholder since there are no private options | ||
*/ | ||
@Slf4j | ||
public abstract class AbstractLineaOptionsPlugin implements BesuPlugin { | ||
private static final String CLI_OPTIONS_PREFIX = "linea"; | ||
private static final Map<String, LineaOptionsPluginConfiguration> LINEA_PLUGIN_CONFIG_MAP = | ||
new HashMap<>(); | ||
|
||
protected abstract Map<String, LineaOptionsPluginConfiguration> getLineaPluginConfigMap(); | ||
|
||
protected LineaOptionsPluginConfiguration getConfigurationByKey(final String key) { | ||
return LINEA_PLUGIN_CONFIG_MAP.get(key); | ||
} | ||
|
||
@Override | ||
public synchronized void register(final BesuContext context) { | ||
final PicoCLIOptions cmdlineOptions = | ||
context | ||
.getService(PicoCLIOptions.class) | ||
.orElseThrow( | ||
() -> | ||
new IllegalStateException( | ||
"Failed to obtain PicoCLI options from the BesuContext")); | ||
|
||
getLineaPluginConfigMap() | ||
.forEach( | ||
(key, pluginConfiguration) -> { | ||
if (!LINEA_PLUGIN_CONFIG_MAP.containsKey(key)) { | ||
LINEA_PLUGIN_CONFIG_MAP.put(key, pluginConfiguration); | ||
cmdlineOptions.addPicoCLIOptions( | ||
CLI_OPTIONS_PREFIX, pluginConfiguration.cliOptions()); | ||
} | ||
}); | ||
} | ||
|
||
@Override | ||
public void beforeExternalServices() { | ||
// TODO: find a way to do this only once and check fro that. | ||
LINEA_PLUGIN_CONFIG_MAP.forEach((opts, config) -> config.initOptionsConfig()); | ||
|
||
LINEA_PLUGIN_CONFIG_MAP.forEach( | ||
(opts, config) -> { | ||
log.debug( | ||
"Configured plugin {} with configuration: {}", getName(), config.optionsConfig()); | ||
}); | ||
} | ||
|
||
@Override | ||
public void start() {} | ||
|
||
@Override | ||
public void stop() { | ||
LINEA_PLUGIN_CONFIG_MAP.clear(); | ||
} | ||
} |
74 changes: 0 additions & 74 deletions
74
...tization/src/main/java/net/consensys/linea/plugins/AbstractLineaPrivateOptionsPlugin.java
This file was deleted.
Oops, something went wrong.
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
24 changes: 24 additions & 0 deletions
24
arithmetization/src/main/java/net/consensys/linea/plugins/LineaCliOptions.java
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,24 @@ | ||
/* | ||
* Copyright Consensys Software Inc. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with | ||
* the License. You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on | ||
* an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the | ||
* specific language governing permissions and limitations under the License. | ||
* | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
package net.consensys.linea.plugins; | ||
|
||
public interface LineaCliOptions { | ||
LineaOptionsConfiguration toDomainObject(); | ||
|
||
default LineaOptionsPluginConfiguration asPluginConfig() { | ||
return new LineaOptionsPluginConfiguration(this, this::toDomainObject); | ||
} | ||
} |
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
34 changes: 34 additions & 0 deletions
34
...metization/src/main/java/net/consensys/linea/plugins/LineaOptionsPluginConfiguration.java
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,34 @@ | ||
/* | ||
* Copyright Consensys Software Inc. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with | ||
* the License. You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on | ||
* an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the | ||
* specific language governing permissions and limitations under the License. | ||
* | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
package net.consensys.linea.plugins; | ||
|
||
import java.util.function.Supplier; | ||
|
||
import lombok.Getter; | ||
import lombok.RequiredArgsConstructor; | ||
import lombok.experimental.Accessors; | ||
|
||
@Accessors(fluent = true) | ||
@RequiredArgsConstructor | ||
public class LineaOptionsPluginConfiguration { | ||
@Getter private final LineaCliOptions cliOptions; | ||
private final Supplier<LineaOptionsConfiguration> optionsConfigSupplier; | ||
@Getter private LineaOptionsConfiguration optionsConfig; | ||
|
||
public void initOptionsConfig() { | ||
optionsConfig = optionsConfigSupplier.get(); | ||
} | ||
} |
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
Oops, something went wrong.