Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can I run a one-liner using Meteor Shell?

Tags:

meteor

As I develop useful one-liners, it'd be handy to be able to run meteor shell, passing it the one-liner, and expecting that it will exit when done. Some syntax such as this, perhaps ?

meteor shell -e 'Meteor.users.remove({})'

Is this a feature request, or does it already exist already ?

Supplemental: I picture adding several of these scripts to package.json so they can be shared by all developers on the project.

like image 213
Dean Radcliffe Avatar asked Feb 10 '23 23:02

Dean Radcliffe


1 Answers

Here's an Expect program for scripting the Meteor shell. You can either run a separate file or run a command directly. Usage:

./mshell -f runThisFile.js
./mshell -e 'console.log("foo")'

Here's the code (License: MIT). Save to a file (mshell, or whatever you choose) and make executable:

#!/usr/bin/expect --
set timeout 3
spawn meteor shell
expect "> "
set firstArg [lindex $argv 0]
set secondArg [lindex $argv 1]
if { $firstArg == "-f" } {
  send [exec cat $secondArg]
  send "\n"
} elseif { $firstArg == "-e" } {
  send "$secondArg\n"
}
expect "true"
send "\x04"
expect "Shell exiting...\n"

On Ubuntu I ran sudo apt-get install expect to install Expect prior to running this program.

Clearly we'd rather running scripts or one-liners were built into meteor shell, so let's just consider this a proof-of-concept.

like image 84
Adam Monsen Avatar answered Mar 20 '23 19:03

Adam Monsen