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

Design: allow onyo set to set different values for the same key across multiple assets #710

Closed
aqw opened this issue Oct 30, 2024 · 5 comments
Labels
design Design decisions in need of discussion

Comments

@aqw
Copy link
Collaborator

aqw commented Oct 30, 2024

Currently, onyo set only allows a key to be defined once:

$ onyo set --keys serial={123,456} -a warehouse/extdrive_sandisk_sdssde61-2t00.faux64CkBh warehouse/extdrive_sandisk_sdssde61-2t00.faux9t7xUH
usage: onyo set [-h] -k KEY [KEY ...] -a ASSET [ASSET ...] [-m MESSAGE] [--no-auto-message]

onyo set: error: Duplicate key 'serial' found.
Keys must not be given multiple times.

I like the idea of matching what we do in onyo new, where we do allow multiple keys to be specified, as long as they are either just once, or the exact same N number of times.

The twist here would be that N must also match the number of assets passed to --asset.

$ onyo new --help
[...]
  -k, --keys KEY [KEY ...]
                        KEY-VALUE pairs to populate content of new assets.
                        
                        Each KEY can be defined either 1 or N times (where N is the number
                        of assets to be created). A KEY that is declared once will apply
                        to all new assets, otherwise each will be applied to each new asset
                        in the order they were declared.
                        
                        For example, create three new laptops with different serials:
                        
                        $ onyo new --keys type=laptop make=apple model=macbookpro serial=1 serial=2 serial=3 --directory shelf/
                        
                        Shell brace-expansion makes this even more succinct:
                        
                        $ onyo new --keys type=laptop make=apple model=macbookpro serial={1,2,3} --directory shelf/
                        
                        Dictionary subkeys can be addressed using a period (e.g. model.name,
                        model.year, etc.)
[...]
@aqw aqw added the design Design decisions in need of discussion label Oct 30, 2024
@TobiasKadelka
Copy link
Collaborator

I like the idea of matching what we do in onyo new, where we do allow multiple keys to be specified, as long as they are either just once, or the exact same N number of times.

Fully agree. I literally assumed this would already be the case, because it should be. I like onyo news behavior a lot.

@bpoldrack
Copy link
Collaborator

I think it's a little less useful than in new, because it also needs to match the order of the given paths, which kinda means you can't use shell expansion of paths because you can't be sure of the order.
Doesn't speak against it, though.

Question is: Is there a way that makes it easier to generate the call programmatically? Would an onyo.cli.asset key help with that?

@aqw
Copy link
Collaborator Author

aqw commented Oct 31, 2024

because it also needs to match the order of the given paths, which kinda means you can't use shell expansion of paths because you can't be sure of the order

Yes and no.

Brace expansion's is ordered, which I imagine will be the most common case here. Globbing.... I don't know if that's defined in POSIX or not, but I do know that bash's globbing is alphabetical. But onyo get is always available, which has sorting.

Other times, order doesn't matter.

As a concrete example, Ralf set the inventory number as the serial for 10 identical external drives. Ignoring the idea of being able to reference other keys (which I've been thinking about recently), I wanted to do:

onyo set --keys inventory.fzj={1,2,3,4,5,6,7,8,9,10} serial=faux -a warehouse/extdrive_sandisk_*

What would take this all further is the ability to reference other keys within the same asset. Something f-string like:

onyo set --keys inventory.fzj="f'{serial}'" serial=faux -a warehouse/extdrive_sandisk_*

That would improve the ergonomics for use-cases that don't care about the order of what is passed into the query, just that it's grouped together when executed within an asset. This would be most powerful with #684

It's a separate issue from this one, but wanted to point it out. It would also allow for renaming a key, etc:

onyo set --keys new="f'{old}'" old='<unset>' -a warehouse/extdrive_sandisk_*

@bpoldrack
Copy link
Collaborator

On that note, referencing #714 here.

@aqw
Copy link
Collaborator Author

aqw commented Nov 5, 2024

Closing in favor of #717

@aqw aqw closed this as completed Nov 5, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
design Design decisions in need of discussion
Projects
None yet
Development

No branches or pull requests

3 participants