databricks / click

The "Command Line Interactive Controller for Kubernetes"
Apache License 2.0
1.49k stars 84 forks source link

Implementation of "last" command #205

Closed bazhenov closed 2 years ago

bazhenov commented 2 years ago

Implementation of last command according to #204.

Implementation is based on range command and at the moment is not respecting KObj type. So for example if query is jobs

 ####   Name                            Completions   Duration   Age
═════════════════════════════════════════════════════════════════════════
    0   etl-fan469-cronjob-1666047600   1/1           20s        2d 16h
    1   etl-fan469-cronjob-1666134000   1/1           21s        1d 16h
    2   etl-fan469-cronjob-1666220400   1/1           28s        16h 54m
    3   etl-fan790-cronjob-1664751600   1/1           15m 50s    17d 16h
    4   etl-fan790-cronjob-1665604800   1/1           14m 59s    7d 19h
    5   etl-fan790-cronjob-1666209600   1/1           15m 53s    19h 54m
─────────────────────────────────────────────────────────────────────────

The last command will print

 ####   Name                            Type          Namespace
═══════════════════════════════════════════════════════════════════
    0   etl-fan469-cronjob-1666047600   StatefulSet   default
    1   etl-fan469-cronjob-1666134000   StatefulSet   default
    2   etl-fan469-cronjob-1666220400   StatefulSet   default
    3   etl-fan790-cronjob-1664751600   StatefulSet   default
    4   etl-fan790-cronjob-1665604800   StatefulSet   default
    5   etl-fan790-cronjob-1666209600   StatefulSet   default
───────────────────────────────────────────────────────────────────

It's possible to preserve CellSpec, although it's will be much more intrusive from the perspective of Env struct.

nicklan commented 2 years ago

Thanks! I think it would actually make sense to just save the table created in table::print_table into the env for this. That would happen here: https://github.com/databricks/click/blob/master/src/command/mod.rs#L250

So table::print_table would return the created table, and then set_last_objs could take an Option<Table> and save it.

I think this command will be much more useful if it can just reprint the whole table.

There are a couple places where we don't create a whole table (like in crd.rs). For now we can just pass None for the table and fall back to what you're doing here.

bazhenov commented 2 years ago

Yes, indeed. I'm working on it.

bazhenov commented 2 years ago

Ок, now KObj formatting rules are preserved