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

add option to output fsinfo as raw filenames #13

Closed
remcoder opened this issue Jul 19, 2016 · 6 comments
Closed

add option to output fsinfo as raw filenames #13

remcoder opened this issue Jul 19, 2016 · 6 comments
Milestone

Comments

@remcoder
Copy link
Contributor

Consuming the fsinfo output with other tools is cumbersome currently. Here's a real life example.

I wanted to remove all *.lc files from the filesystem and I figured I could just iterate over the list of files using a simple bash script. This was a little more involved as:

  • the default output has additional cruft (although it's nice for a human use)
  • json output is actually not that easy to use from a bash script
  • status messages are printed despite --silent (see --silent is not completely silent #12)

The script that I ended up with was this:

for file in `nodemcu-tool fsinfo --json | tail -n +2 | jq .files[].name -r | grep .lc`
do
  echo "removing ${file}"
  nodemcu-tool remove ${file}
done

Here I used tail to skip the first line, which is a status message. Then I used jq to parse the json output and turn it into a plain list of filenames.

I think this should be as easy as:

for file in `nodemcu-tool fsinfo --raw | grep .lc`
do
  echo "removing ${file}"
  nodemcu-tool remove ${file}
done
@AndiDittrich
Copy link
Owner

maybe it is a better idea to add wildcard/glob support to the remove command ?

adding support for a "raw" format to the fsinfo command is pretty easy, if you like i will add it asap

@remcoder
Copy link
Contributor Author

I guess wildcard support for remove would be the best solution for the problem I had. This probably more directly useful to other users as well.

@AndiDittrich AndiDittrich added this to the v1.7.0 milestone Jul 24, 2016
@AndiDittrich
Copy link
Owner

AndiDittrich commented Jul 24, 2016

--raw option is added to the fsinfo command. you can try it out using the current master branch

The Format is: <filename>\t<size>\n

Example 1 - RAW Format

andi@sapphire:~/Development/IoT/NodeMCU-Tool$ ./nodemcu-tool fsinfo --raw
dev/f2.lc       96
helloworld.lua  382
f3.lua  19
f2.lua  19
helloworld.lc   492
dev/f1.lc       96
dev/f3.lc       96
f1.lua  18

Example 2 - Extract the filenames

andi@sapphire:~/Development/IoT/NodeMCU-Tool$ ./nodemcu-tool fsinfo --raw | cut -f1
dev/f2.lc
helloworld.lua
f3.lua
f2.lua
helloworld.lc
dev/f1.lc
dev/f3.lc
f1.lua

@remcoder
Copy link
Contributor Author

Nice work. Personally I'd expect a raw output to be nothing but filenames. No need for file sizes. What do you think?

@AndiDittrich
Copy link
Owner

changed :)

@remcoder
Copy link
Contributor Author

That's actually really cool! Awesome ;-)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants