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

[3.2] Build framework for leap-util #150

Merged
merged 24 commits into from
Oct 4, 2022
Merged
Show file tree
Hide file tree
Changes from 17 commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
d961205
Scaffold, putting cli11 subcommands in separate files
vladtr Aug 23, 2022
97c1980
Added autocompletion for bash
vladtr Aug 25, 2022
54b7eac
+=blocklog, initial raw port
vladtr Sep 7, 2022
1a0d3ef
+=actions_blocklog
vladtr Sep 7, 2022
8bc0826
remove accidental clang-format checkin lol
vladtr Sep 7, 2022
6096916
Define cli option for displaying lots of help
vladtr Sep 7, 2022
48d55ef
Added boilerplate for snapshot subcommand
vladtr Sep 8, 2022
613627f
Added handling of return code
vladtr Sep 12, 2022
45e33e5
Moved cli11 in interface only lib, adjusted cleos and leap-util to us…
vladtr Sep 14, 2022
4829bcf
Added bash-complete scripts for both leap-util and cleos
vladtr Sep 14, 2022
acc1a62
Simplified makefile
vladtr Sep 14, 2022
134c448
Linting and cleanup
vladtr Sep 14, 2022
75ffc6b
Updated CLI11 header to the latest
vladtr Sep 19, 2022
08e0f22
Added chain subcomand, refactoring, bugfixes
vladtr Sep 20, 2022
e592a4a
Multiple changes
vladtr Sep 23, 2022
511f6db
Removet leftovers of genesis from chain-state sc
vladtr Sep 23, 2022
57cbae4
Added bash-completions configs to leap-util and cleos
vladtr Sep 26, 2022
90ce207
Addressing feedback, part one
vladtr Sep 30, 2022
bb462ef
Replaced hardcoded leap-util name with var
vladtr Sep 30, 2022
d198de9
Ditched ilog, added constraints
vladtr Sep 30, 2022
efd9534
Cleaned-up some of block-log stuff
vladtr Sep 30, 2022
294fa45
+=constraint for sc
vladtr Sep 30, 2022
94749d1
install path fix
vladtr Sep 30, 2022
94bee32
Initialize all subcommands flags to false
vladtr Oct 3, 2022
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
8 changes: 8 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -244,6 +244,14 @@ install(FILES libraries/yubihsm/LICENSE DESTINATION ${CMAKE_INSTALL_FULL_DATAROO
install(FILES libraries/eos-vm/LICENSE DESTINATION ${CMAKE_INSTALL_FULL_DATAROOTDIR}/licenses/leap/ RENAME LICENSE.eos-vm COMPONENT base)
install(FILES libraries/fc/libraries/ff/LICENSE DESTINATION ${CMAKE_INSTALL_FULL_DATAROOTDIR}/licenses/leap/ RENAME LICENSE.libff COMPONENT base)

configure_file(${CMAKE_SOURCE_DIR}/programs/leap-cli11/bash-completion/completions/leap-util
${CMAKE_BINARY_DIR}/programs/leap-cli11/bash-completion/completions/leap-util COPYONLY)
configure_file(${CMAKE_SOURCE_DIR}/programs/leap-cli11/bash-completion/completions/cleos
${CMAKE_BINARY_DIR}/programs/leap-cli11/bash-completion/completions/cleos COPYONLY)

install(FILES programs/leap-cli11/bash-completion/completions/leap-util DESTINATION ${CMAKE_INSTALL_FULL_DATAROOTDIR}/bash-completion/completions COMPONENT base)
install(FILES programs/leap-cli11/bash-completion/completions/cleos DESTINATION ${CMAKE_INSTALL_FULL_DATAROOTDIR}/bash-completion/completions COMPONENT base)

add_custom_target(dev-install
COMMAND "${CMAKE_COMMAND}" --build "${CMAKE_BINARY_DIR}"
COMMAND "${CMAKE_COMMAND}" --install "${CMAKE_BINARY_DIR}"
Expand Down
2 changes: 2 additions & 0 deletions programs/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
add_subdirectory( leap-cli11 )
linh2931 marked this conversation as resolved.
Show resolved Hide resolved
add_subdirectory( nodeos )
add_subdirectory( cleos )
add_subdirectory( keosd )
add_subdirectory( eosio-launcher )
add_subdirectory( eosio-blocklog )
add_subdirectory( leap-util )
4 changes: 2 additions & 2 deletions programs/cleos/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
configure_file(help_text.cpp.in help_text.cpp @ONLY)
configure_file(config.hpp.in config.hpp ESCAPE_QUOTES)
add_executable( ${CLI_CLIENT_EXECUTABLE_NAME} main.cpp httpc.cpp "${CMAKE_CURRENT_BINARY_DIR}/help_text.cpp" localize.hpp "${CMAKE_CURRENT_BINARY_DIR}/config.hpp" CLI11.hpp)
add_executable( ${CLI_CLIENT_EXECUTABLE_NAME} main.cpp httpc.cpp "${CMAKE_CURRENT_BINARY_DIR}/help_text.cpp" localize.hpp "${CMAKE_CURRENT_BINARY_DIR}/config.hpp")
if( UNIX AND NOT APPLE )
set(rt_library rt )
endif()
Expand All @@ -11,7 +11,7 @@ set(LOCALEDOMAIN ${CLI_CLIENT_EXECUTABLE_NAME})
target_include_directories(${CLI_CLIENT_EXECUTABLE_NAME} PUBLIC ${CMAKE_CURRENT_BINARY_DIR} ${CMAKE_CURRENT_SOURCE_DIR})

target_link_libraries( ${CLI_CLIENT_EXECUTABLE_NAME}
PRIVATE appbase version chain_api_plugin producer_plugin chain_plugin http_plugin eosio_chain fc ${CMAKE_DL_LIBS} ${PLATFORM_SPECIFIC_LIBS} )
PRIVATE appbase version leap-cli11 chain_api_plugin producer_plugin chain_plugin http_plugin eosio_chain fc ${CMAKE_DL_LIBS} ${PLATFORM_SPECIFIC_LIBS} )


copy_bin( ${CLI_CLIENT_EXECUTABLE_NAME} )
Expand Down
38 changes: 20 additions & 18 deletions programs/cleos/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,8 @@ Usage: ./cleos create account [OPTIONS] creator name OwnerKey ActiveKey
#include <fc/io/fstream.hpp>

#define CLI11_HAS_FILESYSTEM 0
#include "CLI11.hpp"
#include <cli11/CLI11.hpp>

#include "help_text.hpp"
#include "localize.hpp"
#include "config.hpp"
Expand Down Expand Up @@ -1137,8 +1138,8 @@ struct register_producer_subcommand {
auto register_producer = actionRoot->add_subcommand("regproducer", localized("Register a new producer"));
register_producer->add_option("account", producer_str, localized("The account to register as a producer"))->required();
register_producer->add_option("producer_key", producer_key_str, localized("The producer's public key"))->required();
register_producer->add_option("url", url, localized("The URL where info about producer can be found"), true);
register_producer->add_option("location", loc, localized("Relative location for purpose of nearest neighbor scheduling"), true);
register_producer->add_option<string>("url", url, localized("The URL where info about producer can be found"))->capture_default_str();
register_producer->add_option("location", loc, localized("Relative location for purpose of nearest neighbor scheduling"))->capture_default_str();
add_standard_transaction_options_plus_signing(register_producer, "account@active");


Expand Down Expand Up @@ -2402,7 +2403,7 @@ void get_account( const string& accountName, const string& coresym, bool json_fo
// looks a little crazy, but should be efficient
cache.insert( std::make_pair(name, std::move(perm)) );
}

using dfs_fn_t = std::function<void (const eosio::chain_apis::permission&, int)>;
std::function<void (account_name, int, dfs_fn_t&)> dfs_exec = [&]( account_name name, int depth, dfs_fn_t& f ) -> void {
auto& p = cache.at(name);
Expand Down Expand Up @@ -2456,15 +2457,15 @@ void get_account( const string& accountName, const string& coresym, bool json_fo
dfs_exec( r, 0, print_links);
}

// print linked actions
// print linked actions
std::cout << indent << "eosio.any: " << std::endl;
for (const auto& it : res.eosio_any_linked_actions) {
auto action_value = it.action ? it.action->to_string() : std::string("*");
std::cout << indent << indent << it.account << "::" << action_value << std::endl;
}

std::cout << std::endl;

auto to_pretty_net = []( int64_t nbytes, uint8_t width_for_units = 5 ) {
if(nbytes == -1) {
// special case. Treat it as unlimited
Expand Down Expand Up @@ -2723,15 +2724,16 @@ int main( int argc, char** argv ) {
wallet_url = default_wallet_url;

CLI::App app{"Command Line Interface to EOSIO Client"};
app.set_help_all_flag("--help-all", "Show all help");
app.require_subcommand();
// Hide obsolete options by putting them into a group with an empty name.
app.add_option( "-H,--host", obsoleted_option_host_port, localized("The host where ${n} is running", ("n", node_executable_name)) )->group("");
app.add_option( "-p,--port", obsoleted_option_host_port, localized("The port where ${n} is running", ("n", node_executable_name)) )->group("");
app.add_option( "--wallet-host", obsoleted_option_host_port, localized("The host where ${k} is running", ("k", key_store_executable_name)) )->group("");
app.add_option( "--wallet-port", obsoleted_option_host_port, localized("The port where ${k} is running", ("k", key_store_executable_name)) )->group("");

app.add_option( "-u,--url", ::default_url, localized( "The http/https URL where ${n} is running", ("n", node_executable_name)), true );
app.add_option( "--wallet-url", wallet_url, localized("The http/https URL where ${k} is running", ("k", key_store_executable_name)), true );
app.add_option( "-u,--url", ::default_url, localized( "The http/https URL where ${n} is running", ("n", node_executable_name)))->capture_default_str();
app.add_option( "--wallet-url", wallet_url, localized("The http/https URL where ${k} is running", ("k", key_store_executable_name)))->capture_default_str();

app.add_option( "--abi-file", abi_files_overide_callback, localized("In form of <contract name>:<abi file path>, use a local abi file for serialization and deserialization instead of getting the abi data from the blockchain; repeat this option to pass multiple abi files for different contracts"))->type_size(0, 1000);
app.add_option( "-r,--header", header_opt_callback, localized("Pass specific HTTP header; repeat this option to pass multiple headers"));
Expand Down Expand Up @@ -2880,7 +2882,7 @@ int main( int argc, char** argv ) {
string str_chain_id;
auto validate_signatures = validate->add_subcommand("signatures", localized("Validate signatures and recover public keys"));
validate_signatures->add_option("transaction", trx_json_to_validate,
localized("The JSON string or filename defining the transaction to validate"), true)->required();
localized("The JSON string or filename defining the transaction to validate"))->required()->capture_default_str();
validate_signatures->add_option("-c,--chain-id", str_chain_id, localized("The chain id that will be used in signature verification"));

validate_signatures->callback([&] {
Expand Down Expand Up @@ -3577,7 +3579,7 @@ int main( int argc, char** argv ) {
string wallet_name = "default";
string password_file;
auto createWallet = wallet->add_subcommand("create", localized("Create a new wallet locally"));
createWallet->add_option("-n,--name", wallet_name, localized("The name of the new wallet"), true);
createWallet->add_option("-n,--name", wallet_name, localized("The name of the new wallet"))->capture_default_str();
createWallet->add_option("-f,--file", password_file, localized("Name of file to write wallet password output to. (Must be set, unless \"--to-console\" is passed"));
createWallet->add_flag( "--to-console", print_console, localized("Print password to console."));
createWallet->callback([&wallet_name, &password_file, &print_console] {
Expand Down Expand Up @@ -3683,8 +3685,8 @@ int main( int argc, char** argv ) {
// create a key within wallet
string wallet_create_key_type;
auto createKeyInWallet = wallet->add_subcommand("create_key", localized("Create private key within wallet"));
createKeyInWallet->add_option("-n,--name", wallet_name, localized("The name of the wallet to create key into"), true);
createKeyInWallet->add_option("key_type", wallet_create_key_type, localized("Key type to create (K1/R1)"), true)->type_name("K1/R1");
createKeyInWallet->add_option("-n,--name", wallet_name, localized("The name of the wallet to create key into"))->capture_default_str();
createKeyInWallet->add_option("key_type", wallet_create_key_type, localized("Key type to create (K1/R1)"))->type_name("K1/R1")->capture_default_str();
createKeyInWallet->callback([&wallet_name, &wallet_create_key_type] {
//an empty key type is allowed -- it will let the underlying wallet pick which type it prefers
fc::variants vs = {fc::variant(wallet_name), fc::variant(wallet_create_key_type)};
Expand All @@ -3709,7 +3711,7 @@ int main( int argc, char** argv ) {

// list private keys
auto listPrivKeys = wallet->add_subcommand("private_keys", localized("List of private keys from an unlocked wallet in wif or PVT_R1 format."));
listPrivKeys->add_option("-n,--name", wallet_name, localized("The name of the wallet to list keys from"), true);
listPrivKeys->add_option("-n,--name", wallet_name, localized("The name of the wallet to list keys from"))->capture_default_str();
listPrivKeys->add_option("--password", wallet_pw, localized("The password returned by wallet create"))->expected(0, 1);
listPrivKeys->callback([&wallet_name, &wallet_pw] {
prompt_for_wallet_password(wallet_pw, wallet_name);
Expand Down Expand Up @@ -3738,7 +3740,7 @@ int main( int argc, char** argv ) {

auto sign = app.add_subcommand("sign", localized("Sign a transaction"));
sign->add_option("transaction", trx_json_to_sign,
localized("The JSON string or filename defining the transaction to sign"), true)->required();
localized("The JSON string or filename defining the transaction to sign"))->required()->capture_default_str();
sign->add_option("-k,--private-key", str_private_key, localized("The private key that will be used to sign the transaction"))->expected(0, 1);
sign->add_option("--public-key", str_public_key, localized("Ask ${exec} to sign with the corresponding private key of the given public key", ("exec", key_store_executable_name)));
sign->add_option("-c,--chain-id", str_chain_id, localized("The chain id that will be used to sign the transaction"));
Expand All @@ -3749,7 +3751,7 @@ int main( int argc, char** argv ) {
EOSC_ASSERT( str_private_key.empty() || str_public_key.empty(), "ERROR: Either -k/--private-key or --public-key or none of them can be set" );
fc::variant trx_var = json_from_file_or_string(trx_json_to_sign);

// If transaction was packed, unpack it before signing
// If transaction was packed, unpack it before signing
bool was_packed_trx = false;
if( trx_var.is_object() ) {
fc::variant_object& vo = trx_var.get_object();
Expand Down Expand Up @@ -3826,9 +3828,9 @@ int main( int argc, char** argv ) {
auto actionsSubcommand = push->add_subcommand("action", localized("Push a transaction with a single action"));
actionsSubcommand->fallthrough(false);
actionsSubcommand->add_option("account", contract_account,
localized("The account providing the contract to execute"), true)->required();
localized("The account providing the contract to execute"))->required()->capture_default_str();
actionsSubcommand->add_option("action", action,
localized("A JSON string or filename defining the action to execute on the contract"), true)->required();
localized("A JSON string or filename defining the action to execute on the contract"))->required()->capture_default_str();
actionsSubcommand->add_option("data", data, localized("The arguments to the contract"))->required();

add_standard_transaction_options_plus_signing(actionsSubcommand);
Expand Down Expand Up @@ -4427,7 +4429,7 @@ int main( int argc, char** argv ) {
} catch (const fc::exception& e) {
return handle_error(e);
} catch (const std::exception& e) {
return handle_error(fc::std_exception_wrapper::from_current_exception(e));
return handle_error(fc::std_exception_wrapper::from_current_exception(e));
}

return 0;
Expand Down
2 changes: 2 additions & 0 deletions programs/leap-cli11/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
add_library(leap-cli11 INTERFACE)
target_include_directories(leap-cli11 INTERFACE include)
spoonincode marked this conversation as resolved.
Show resolved Hide resolved
26 changes: 26 additions & 0 deletions programs/leap-cli11/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@

## instructions for building custom leap-cli11 library

leap-cli11 interface only library created in order to simplify integration of modified version of command line parsing library cli11

to update included in this library include/cli11/CLI11.hpp file it needs to be (re)geenerated from repository containing forked/modified version of it, in particular:


```bash
git clone git@github.com:AntelopeIO/CLI11.git
spoonincode marked this conversation as resolved.
Show resolved Hide resolved
cd CLI11
mkdir build
cd build
cmake -DCLI11_SINGLE_FILE=ON ..
make -j
```

Resulting single-header will be located in:

```cpp
build/include/CLI11.hpp
```

And is ready to be copied to include/cli11/CLI11.hpp of leap-cli11 library

Automated CLI11 subproject build / import of CLI11.hpp header will be added in feature versions.
linh2931 marked this conversation as resolved.
Show resolved Hide resolved
26 changes: 26 additions & 0 deletions programs/leap-cli11/bash-completion/completions/cleos
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
#/usr/bin/env bash

_cleos_complete()
{
# Get cmdline while ignoring the last word
cmdline=${COMP_LINE}
if [[ "${cmdline:${cmdlinex}-1}" != " " ]]; then
linh2931 marked this conversation as resolved.
Show resolved Hide resolved
cmdline=${COMP_WORDS[@]:0:${COMP_CWORD}}
fi

# Get complete candidates
words=$(${cmdline} --_autocomplete "${COMP_WORDS[${COMP_CWORD}]}")

# Remove candidates that begins with `-` if `-` is not passed as the first character
# TODO: move this logic inside CLI11? including the compgen?
if [[ ! ${COMP_WORDS[${COMP_CWORD}]} = -* ]]; then
words=(${words})
for index in "${!words[@]}" ; do [[ ${words[$index]} =~ ^- ]] && unset -v 'words[$index]' ; done
words="${words[@]}"
fi

# Get matches
COMPREPLY=($(compgen -W "${words}" -- "${COMP_WORDS[${COMP_CWORD}]}"))
}

complete -F _cleos_complete cleos
26 changes: 26 additions & 0 deletions programs/leap-cli11/bash-completion/completions/leap-util
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
#/usr/bin/env bash

_leap_complete()
{
# Get cmdline while ignoring the last word
cmdline=${COMP_LINE}
if [[ "${cmdline:${cmdlinex}-1}" != " " ]]; then
linh2931 marked this conversation as resolved.
Show resolved Hide resolved
cmdline=${COMP_WORDS[@]:0:${COMP_CWORD}}
fi

# Get complete candidates
words=$(${cmdline} --_autocomplete "${COMP_WORDS[${COMP_CWORD}]}")

# Remove candidates that begins with `-` if `-` is not passed as the first character
# TODO: move this logic inside CLI11? including the compgen?
if [[ ! ${COMP_WORDS[${COMP_CWORD}]} = -* ]]; then
words=(${words})
for index in "${!words[@]}" ; do [[ ${words[$index]} =~ ^- ]] && unset -v 'words[$index]' ; done
words="${words[@]}"
fi

# Get matches
COMPREPLY=($(compgen -W "${words}" -- "${COMP_WORDS[${COMP_CWORD}]}"))
}

complete -F _leap_complete leap-util
Loading