mirror of
https://github.com/mgree/ffs.git
synced 2024-08-16 14:50:35 +03:00
change default behavior to modify newlines; update readme
This commit is contained in:
parent
a02d674ae5
commit
5a0100bfb1
76
README.md
76
README.md
@ -15,61 +15,31 @@ know.
|
||||
Run `ffs [mountpoint] [file]` to mount a file at a given mountpoint.
|
||||
|
||||
```shell-session
|
||||
$ ffs mnt json_eg1.json &
|
||||
[1] 80762
|
||||
$ tree mnt
|
||||
mnt
|
||||
└── glossary
|
||||
├── GlossDiv
|
||||
│ ├── GlossList
|
||||
│ │ └── GlossEntry
|
||||
│ │ ├── Abbrev
|
||||
│ │ ├── Acronym
|
||||
│ │ ├── GlossDef
|
||||
│ │ │ ├── GlossSeeAlso
|
||||
│ │ │ │ ├── 0
|
||||
│ │ │ │ └── 1
|
||||
│ │ │ └── para
|
||||
│ │ ├── GlossSee
|
||||
│ │ ├── GlossTerm
|
||||
│ │ ├── ID
|
||||
│ │ └── SortAs
|
||||
│ └── title
|
||||
└── title
|
||||
$ cat object.json
|
||||
{ "name": "Michael Greenberg", "eyes": 2, "fingernails": 10, "human": true }
|
||||
$ ffs -o object_edited.json object.json &
|
||||
[1] 60182
|
||||
$ tree object
|
||||
object
|
||||
├── eyes
|
||||
├── fingernails
|
||||
├── human
|
||||
└── name
|
||||
|
||||
6 directories, 11 files
|
||||
$ cat mnt/glossary/GlossDiv/GlossList/GlossEntry/Abbrev
|
||||
ISO 8879:1986$ cat mnt/glossary/GlossDiv/GlossList/GlossEntry/Acronym
|
||||
SGML$ cat mnt/glossary/title
|
||||
example glossary$ cat json_eg1.json
|
||||
{
|
||||
"glossary": {
|
||||
"title": "example glossary",
|
||||
"GlossDiv": {
|
||||
"title": "S",
|
||||
"GlossList": {
|
||||
"GlossEntry": {
|
||||
"ID": "SGML",
|
||||
"SortAs": "SGML",
|
||||
"GlossTerm": "Standard Generalized Markup Language",
|
||||
"Acronym": "SGML",
|
||||
"Abbrev": "ISO 8879:1986",
|
||||
"GlossDef": {
|
||||
"para": "A meta-markup language, used to create markup languages such as DocBook.",
|
||||
"GlossSeeAlso": ["GML", "XML"]
|
||||
},
|
||||
"GlossSee": "markup"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
$ ps | grep ffs
|
||||
80762 ttys001 0:00.03 ffs mnt json_eg1.json
|
||||
80843 ttys001 0:00.00 grep ffs
|
||||
$ umount mnt
|
||||
[1]+ Done ffs mnt json_eg1.json
|
||||
0 directories, 4 files
|
||||
$ echo Mikey Indiana >object/name
|
||||
$ echo 1 >object/nose
|
||||
$ mkdir object/pockets
|
||||
$ cd object/pockets/
|
||||
$ echo keys >pants
|
||||
$ echo pen >shirt
|
||||
$ cd ..
|
||||
$ cd ..
|
||||
$ umount object
|
||||
$
|
||||
[1]+ Done ffs -o object_edited.json object.json
|
||||
$ cat object_edited.json
|
||||
{"eyes":2,"fingernails":10,"human":true,"name":"Mikey Indiana","nose":1,"pockets":{"pants":"keys","shirt":"pen"}}
|
||||
```
|
||||
|
||||
# External dependencies
|
||||
|
@ -81,7 +81,7 @@ impl Default for Config {
|
||||
gid: 501,
|
||||
filemode: 0o644,
|
||||
dirmode: 0o755,
|
||||
add_newlines: false,
|
||||
add_newlines: true,
|
||||
pad_element_names: true,
|
||||
base64: base64::STANDARD,
|
||||
try_decode_base64: false,
|
||||
|
@ -299,6 +299,7 @@ where
|
||||
if fs.config.add_newlines && contents.ends_with('\n') {
|
||||
contents.truncate(contents.len() - 1);
|
||||
}
|
||||
// TODO 2021-06-24 trim?
|
||||
V::from_string(contents, &fs.config)
|
||||
}
|
||||
Err(_) => V::from_bytes(contents, &fs.config),
|
||||
|
@ -62,9 +62,9 @@ fn main() {
|
||||
.default_value("755")
|
||||
)
|
||||
.arg(
|
||||
Arg::with_name("NEWLINE")
|
||||
.help("Add a newline to the end of values that don't already have them")
|
||||
.long("newline")
|
||||
Arg::with_name("EXACT")
|
||||
.help("Don't add newlines to the end of values that don't already have them (or strip them when loading)")
|
||||
.long("exact")
|
||||
)
|
||||
.arg(
|
||||
Arg::with_name("UNPADDED")
|
||||
@ -145,7 +145,7 @@ fn main() {
|
||||
.init();
|
||||
}
|
||||
|
||||
config.add_newlines = args.is_present("NEWLINE");
|
||||
config.add_newlines = !args.is_present("EXACT");
|
||||
config.pad_element_names = !args.is_present("UNPADDED");
|
||||
config.read_only = args.is_present("READONLY");
|
||||
config.filemode = match u16::from_str_radix(args.value_of("FILEMODE").unwrap(), 8) {
|
||||
|
@ -22,7 +22,7 @@ printf "10" >"${EXP}/fingernails"
|
||||
printf "true" >"${EXP}/human"
|
||||
printf "" >"${EXP}/problems"
|
||||
|
||||
ffs -m "$MNT" ../json/object_null.json &
|
||||
ffs --exact -m "$MNT" ../json/object_null.json &
|
||||
PID=$!
|
||||
sleep 2
|
||||
cd "$MNT"
|
||||
|
@ -22,7 +22,7 @@ printf "10\n" >"${EXP}/fingernails"
|
||||
printf "true\n" >"${EXP}/human"
|
||||
printf "" >"${EXP}/problems"
|
||||
|
||||
ffs --newline -m "$MNT" ../json/object_null.json &
|
||||
ffs -m "$MNT" ../json/object_null.json &
|
||||
PID=$!
|
||||
sleep 2
|
||||
cd "$MNT"
|
||||
|
@ -25,7 +25,7 @@ printf "true" >"${EXP}/human"
|
||||
printf "hi\n" >"${EXP}/greeting"
|
||||
printf "bye" >"${EXP}/farewell"
|
||||
|
||||
ffs -o "$JSON" -m "$MNT" ../json/object.json &
|
||||
ffs --exact -o "$JSON" -m "$MNT" ../json/object.json &
|
||||
PID=$!
|
||||
sleep 2
|
||||
echo hi >"$MNT"/greeting
|
||||
@ -34,8 +34,8 @@ umount "$MNT" || fail unmount
|
||||
sleep 1
|
||||
kill -0 $PID >/dev/null 2>&1 && fail process
|
||||
|
||||
# remount w/o --newline, confirm that they're not there (except for greeting)
|
||||
ffs -m "$MNT" "$JSON" &
|
||||
# remount w/ --exact, confirm that they're not there (except for greeting)
|
||||
ffs --exact -m "$MNT" "$JSON" &
|
||||
sleep 2
|
||||
case $(ls "$MNT") in
|
||||
(eyes*farewell*fingernails*greeting*human*name) ;;
|
||||
|
@ -25,7 +25,7 @@ printf "true" >"${EXP}/human"
|
||||
printf "hi" >"${EXP}/greeting"
|
||||
printf "bye" >"${EXP}/farewell"
|
||||
|
||||
ffs --newline -o "$JSON" -m "$MNT" ../json/object.json &
|
||||
ffs -o "$JSON" -m "$MNT" ../json/object.json &
|
||||
PID=$!
|
||||
sleep 2
|
||||
echo hi >"$MNT"/greeting
|
||||
@ -34,8 +34,8 @@ umount "$MNT" || fail unmount
|
||||
sleep 1
|
||||
kill -0 $PID >/dev/null 2>&1 && fail process
|
||||
|
||||
# remount w/o --newline, confirm that they're not there
|
||||
ffs -m "$MNT" "$JSON" &
|
||||
# remount w/ --exact, confirm that they're not there
|
||||
ffs --exact -m "$MNT" "$JSON" &
|
||||
sleep 2
|
||||
case $(ls "$MNT") in
|
||||
(eyes*farewell*fingernails*greeting*human*name) ;;
|
||||
|
Loading…
Reference in New Issue
Block a user