bug-recutils
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[bug-recutils] Proposal: utility to prompt for user input


From: Leo Famulari
Subject: [bug-recutils] Proposal: utility to prompt for user input
Date: Sun, 18 Oct 2015 18:56:28 -0400

Greetings,

Recently I needed to record some structured data about a collection of
physical objects. I read about recutils a few months ago, so I decided
to try it out. I threw together my first ever recutils record types [1]
and made a couple scripts [2] to streamline the data entry.

The idea of the scripts is this: for a record type, prompt the user to
input data for each field. I usually don't like interactive programs on
the command line, but for data entry I think they are fine.

What I really didn't like about my "solution" is that the fields of the
record types end up being replicated in three different places: in the
record descriptor in the recfile, the script's read-loop, and the
script's invocation of recins. This is because there was no obvious way
to access them programmatically. In this case, there were only two
simple record types so I just handled the triplication manually but even
at this small scale it was annoying and I kept making mistakes.

I saw on the ML archives that people have discussed these issues before
[3]. Has anyone come up with a better solution to this problem?

If not, I will make a program, writerec, that is the (inexact) inverse
of readrec. I'm not sure exactly how it will work, but the basic idea is
that you will give it the name of a record type and a recfile, and it
will parse the record descriptor to decide what fields the user should
be prompted to enter.

My initial plan is for writerec to prompt the user to enter values for
all %allowed fields.

Can anyone think of any special considerations to take into account? Is
there any reason to make it a Bash builtin like readrec or would it work
better as a standalone program like recins, recset, etc?

[1]
# These record descriptors have been simplified for this example
%rec: machine
%key: id
%auto: id
%type: id int
%allowed: size description smell
%mandatory: description 

%rec: connection
%key: id
%auto: id
%type: id int
%allowed: type from to notes
%type: from rec machine
%type: to rec machine
%mandatory: from to

[2]
#!/bin/sh

main() {
        fields="description size smell"
        for field in $fields; do
                printf "%s: " "$field"
                read -r "$field"
        done

        recins -t machine \
-f description -v "$description" \
-f size -v "$size" \
-f smell -v "$smell" \
data.rec

        return 0;
}
main

[3]
Aikido Guy: Easier way to get a list of fields for a record?
http://lists.nongnu.org/archive/html/help-recutils/2013-10/msg00000.html

David J Patrick: RFE; recins -I [type] recfile.rec
http://lists.nongnu.org/archive/html/help-recutils/2011-05/msg00005.html



reply via email to

[Prev in Thread] Current Thread [Next in Thread]