[Freeipa-devel] [PATCH] 228 add function to prompt for entry after multiple results in -find

Jason Gerard DeRose jderose at redhat.com
Tue Jun 9 16:39:15 UTC 2009


On Mon, 2009-06-08 at 17:41 -0400, Rob Crittenden wrote:
> The -find commands right now just dump all the data that was found. This 
> function can be used to display a list of the results so the user can 
> select a specfic record that will be displayed.
> 
> I think that we'll ultimitely implement this within the LDAPObject class 
> to make it easier on plugin developers. What they will need to provide 
> is the format line that will be used and the attributes to display.
> 
> The code looks something like:
> 
>          selected = textui.select_entry(users,
>                                         "%(givenname)s %(sn)s (%(uid)s)",
>                                         ("givenname", "sn", "uid"))
>          if selected == -2:
>              # Don't show anything else
>              return
> 
>          if selected >= 0:
>              users = [users[selected]]
>              counter = 1
> 
>          for u in xrange(counter):
>              cmd = api.Command['user_show']
>              result = cmd(users[u]['uid'].decode('UTF-8'), **options)
>              if callable(cmd.output_for_cli):
>                  for param in cmd.params():
>                      if param.password and param.name in options:
>                          del options[param.name]
>                  (args, options) = cmd.params_2_args_options(**options)
>                  cmd.output_for_cli(self.api.Backend.textui, result, 
> *args, **options)
> 
> This demonstrates the full code in output_for_cli() for the current user 
> plugin. It looks like this to the user:
> 
> % ipa user-find tim
> ---------------
> Found 3 matches
> ---------------
> 1: Tim User (tuser1)
> 2: Tim User (tuser2)
> 3: Tim User (tuser3)
> Choose one: (1 - 3), a for all, q to quit:

I think this is a reasonable approach, although it would be nice to
allow the user just display the details on all the entries also.  This
is important if you want to compare entries, like, "There are 10 Jason's
where I work, I'll search for 'Jason' and find the one I'm looking for
because I forgot the last name."  Dumping all the results (the way we do
now) probably has important scripting use-cases too.

When you have less than 10 or so matches, IHMO the drill down approach
is slower and more cumbersome for the user... it would be faster to
scroll through the results to find the one you want.  I personally feel
we should keep the way we currently do things the default and add an
option for this kind of drill down.  Either way, there should be an
option to switch from one behavior to another.

Another nitpick: the "Found 3 matches" should really be at the bottom of
the list as it's extremely useful in helping the user evaluate their
search, so we don't want it to scroll off the top when there are many
results.

> By doing this in a higher-level class we'll save a lot of coding. We 
> just need to pass in the format string, the list of attributes in that 
> format string and the command to call to display a full entry.
> 
> This also lets us centralize showing an entry to one function instead of 
> splitting it between -find and -show.
> 
> If this is called without a tty (like redirecting to a file) then all 
> entries are returned.
> 
> What this doesn't do is any sort of paging. I'm not sure if we want that 
> or not. If 100 entries are returned this could get pretty ugly.
> 
> rob
> _______________________________________________
> Freeipa-devel mailing list
> Freeipa-devel at redhat.com
> https://www.redhat.com/mailman/listinfo/freeipa-devel




More information about the Freeipa-devel mailing list