Skip to content

move common tools from nu-command to nu-cmd-base#9455

Merged
stormasm merged 4 commits intonushell:mainfrom
amtoine:refactor/move-common-tools-from-nu-commands-to-nu-cmd-base
Jun 22, 2023
Merged

move common tools from nu-command to nu-cmd-base#9455
stormasm merged 4 commits intonushell:mainfrom
amtoine:refactor/move-common-tools-from-nu-commands-to-nu-cmd-base

Conversation

@amtoine
Copy link
Copy Markdown
Member

@amtoine amtoine commented Jun 16, 2023

related to

Description

to support our cratification effort and moving non-1.0 commands outside of the main focus, this PR

  • creates a new nu-cmd-base crate to hold the common structs, traits and functions used by all command-related crates
  • to start the transition, moves the input_handler module from nu-command to nu-cmd-base

User-Facing Changes

$nothing

Tests + Formatting

  • 🟢 toolkit fmt
  • 🟢 toolkit clippy
  • toolkit test
  • toolkit test stdlib

After Submitting

$nothing

@amtoine
Copy link
Copy Markdown
Member Author

amtoine commented Jun 16, 2023

cc/ @stormasm

i've used the following command to isolate the tool items used throughout the nu-command crate:

rg "^use crate" crates/nu-command/src/math/ | lines | parse "{file}:{match}" | get match

which gives, after removing the use crate from the default_context and from the help command which obviously need these imports, we get the following table of items

╭────┬───────────────────────────────────────────────────────────────────────────────────────────────╮
│  1 │ use crate::math::reducers::{reducer_for, Reduce};                                             │
│  2 │ use crate::math::utils::run_with_function;                                                    │
│  3 │ use crate::input_handler::{operate, CmdArgument};                                             │
│  4 │ use crate::input_handler::{operate, CellPathOnlyArgs};                                        │
│  5 │ use crate::formats::to::delimited::merge_descriptors;                                         │
│  6 │ use crate::formats::nu_xml_format::{COLUMN_ATTRS_NAME, COLUMN_CONTENT_NAME, COLUMN_TAG_NAME}; │
│  7 │ use crate::formats::to::delimited::to_delimited_data;                                         │
│  8 │ use crate::math::avg::average;                                                                │
│ 13 │ use crate::input_handler::{operate as general_operate, CmdArgument};                          │
│ 14 │ use crate::util::get_guaranteed_cwd;                                                          │
│ 15 │ use crate::date::utils::parse_date_from_string;                                               │
│ 16 │ use crate::{generate_strftime_list, parse_date_from_string};                                  │
│ 17 │ use crate::formats::value_to_string;                                                          │
│ 18 │ use crate::help::highlight_search_string;                                                     │
│ 19 │ use crate::hook::eval_hook;                                                                   │
│ 20 │ use crate::database::values::definitions::{db_row::DbRow, db_table::DbTable};                 │
│ 21 │ use crate::database::values::sqlite::open_sqlite_db;                                          │
│ 22 │ use crate::ExternalCommand;                                                                   │
│ 23 │ use crate::network::http::client::{                                                           │
│ 24 │ use crate::formats::value_to_json_value;                                                      │
│ 25 │ use crate::database::values::definitions::db_row::DbRow;                                      │
│ 26 │ use crate::filesystem::util::FileStructure;                                                   │
│ 27 │ use crate::progress_bar;                                                                      │
│ 28 │ use crate::database::SQLiteDatabase;                                                          │
│ 29 │ use crate::DirBuilder;                                                                        │
│ 30 │ use crate::DirInfo;                                                                           │
│ 31 │ use crate::{DirBuilder, DirInfo, FileInfo};                                                   │
│ 32 │ use crate::filesystem::cd_query::query;                                                       │
│ 33 │ use crate::debug::inspect_table::{                                                            │
│ 34 │ use crate::{grapheme_flags, util};                                                            │
│ 35 │ use crate::grapheme_flags;                                                                    │
│ 36 │ use crate::operate;                                                                           │
╰────┴───────────────────────────────────────────────────────────────────────────────────────────────╯

❓ do we move them all to the new nu-cmd-base crate? 😮

@stormasm
Copy link
Copy Markdown
Contributor

@amtoine

I think to be on the safe side of things we should move those helper functions over as we need them...

In other words the first one I would move in this PR is input_handler because the bytes command will need it...

So input_handler will be our first command in nu-cmd-base

and it will be up and "running" / landed

then I will do the bytes command

and then as we want to move more commands

we move the helper commands first and then the actual commands...

What do you think of this ?

@amtoine
Copy link
Copy Markdown
Member Author

amtoine commented Jun 21, 2023

sounds good to me 👍

so let's move input_handler 😏

@amtoine amtoine marked this pull request as ready for review June 21, 2023 17:22
@stormasm
Copy link
Copy Markdown
Contributor

@kubouch @fdncred you all can go ahead and land this PR if you think its ok...

or I will check in with you all tomorrow morning after I wake up and we can figure out what to do....

thanks !

@stormasm
Copy link
Copy Markdown
Contributor

all this PR is doing is moving input_handler to a new crate called nu-cmd-base

@amtoine
Copy link
Copy Markdown
Member Author

amtoine commented Jun 22, 2023

or I will check in with you all tomorrow morning after I wake up and we can figure out what to do....

have you had the time to gain some insights into this? 😋

@stormasm stormasm merged commit 78697bb into nushell:main Jun 22, 2023
@stormasm
Copy link
Copy Markdown
Contributor

@amtoine I went ahead and merged this as it was blocking me making forward progress on moving the bytes command to nu-cmd-extra...

Now I should be able to land that PR as well....

@stormasm
Copy link
Copy Markdown
Contributor

And now that we have seen some other PRs fail in the exact same spot with Python virtualenv I was assured the issue is NOT related to this PR 😄

fnordpig pushed a commit to fnordpig/nushell that referenced this pull request Jun 23, 2023
related to 
- nushell#9404

# Description
to support our cratification effort and moving non-1.0 commands outside
of the main focus, this PR
- creates a new `nu-cmd-base` crate to hold the common structs, traits
and functions used by all command-related crates
- to start the transition, moves the `input_handler` module from
`nu-command` to `nu-cmd-base`

# User-Facing Changes
```
$nothing
```

# Tests + Formatting
- 🟢 `toolkit fmt`
- 🟢 `toolkit clippy`
- ⚫ `toolkit test`
- ⚫ `toolkit test stdlib`

# After Submitting
```
$nothing
```
@amtoine amtoine deleted the refactor/move-common-tools-from-nu-commands-to-nu-cmd-base branch June 23, 2023 17:07
stormasm added a commit that referenced this pull request Jun 23, 2023
now that #9455 has landed we can move the bytes command to nu-cmd-extra

in concert with

moving nu_command::util to nu-cmd-base
stormasm pushed a commit that referenced this pull request Jul 6, 2023
requires
- #9455

# ⚙️ Description
in this PR i move the commands we've all agreed, in the core team, to
move out of the core Nushell to the `extra` feature.

> **Warning**
> in the first commits here, i've
> - moved the implementations to `nu-cmd-extra`
> - removed the declaration of all the commands below from `nu-command`
> - made sure the commands were not available anymore with `cargo run --
-n`

## the list of commands to move
with the current command table downloaded as `commands.csv`, i've run
```bash
let commands = (
    open commands.csv
    | where is_plugin == "FALSE" and category != "deprecated"
    | select name category "approv. %"
    | rename name category approval
    | insert treated {|it| (
        ($it.approval == 100) or                # all the core team agreed on them
        ($it.name | str starts-with "bits") or  # see #9241
        ($it.name | str starts-with "dfr")      # see #9327
    )}
)
```
to preprocess them and then
```bash
$commands | where {|it| (not $it.treated) and ($it.approval == 0)}
```
to get all untreated commands with no approval, which gives
```
╭────┬───────────────┬─────────┬─────────────┬──────────╮
│  # │     name      │ treated │  category   │ approval │
├────┼───────────────┼─────────┼─────────────┼──────────┤
│  0 │ fmt           │ false   │ conversions │        0 │
│  1 │ each while    │ false   │ filters     │        0 │
│  2 │ roll          │ false   │ filters     │        0 │
│  3 │ roll down     │ false   │ filters     │        0 │
│  4 │ roll left     │ false   │ filters     │        0 │
│  5 │ roll right    │ false   │ filters     │        0 │
│  6 │ roll up       │ false   │ filters     │        0 │
│  7 │ rotate        │ false   │ filters     │        0 │
│  8 │ update cells  │ false   │ filters     │        0 │
│  9 │ decode hex    │ false   │ formats     │        0 │
│ 10 │ encode hex    │ false   │ formats     │        0 │
│ 11 │ from url      │ false   │ formats     │        0 │
│ 12 │ to html       │ false   │ formats     │        0 │
│ 13 │ ansi gradient │ false   │ platform    │        0 │
│ 14 │ ansi link     │ false   │ platform    │        0 │
│ 15 │ format        │ false   │ strings     │        0 │
╰────┴───────────────┴─────────┴─────────────┴──────────╯
```
# 🖌️ User-Facing Changes
```
$nothing
```

# 🧪 Tests + Formatting
- ⚫ `toolkit fmt`
- ⚫ `toolkit clippy`
- ⚫ `toolkit test`
- ⚫ `toolkit test stdlib`

# 📖 After Submitting
```
$nothing
```

# 🔍 For reviewers
```bash
$commands | where {|it| (not $it.treated) and ($it.approval == 0)} | each {|command|
    try {
        help $command.name | ignore
    } catch {|e|
        $"($command.name): ($e.msg)"
    }
}
```
should give no output in `cargo run --features extra -- -n` and a table
with 16 lines in `cargo run -- -n`
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants