Code Monkey home page Code Monkey logo

ezscr's Introduction

EzScr

Portable and easy Nimscript runner.

With this tool, you can bundle a lot of scripts and run it everywhere

No extra binary needed

Installation

First install Nim, then run:

nimble install ezscr

And the command ezscr will be available in your terminal. (Make sure that Nimble bin dir is on your PATH)

Usage

The usage is very simple and there's just 4 commands that you need to learn!

See some examples here

new: Create new script (and setup structure)

Run

ezscr new <SCRIPT NAMES...> [-s]

-s makes the script secret, and needs to provide the secret (password) that can be configured at config.yaml (that is created with command new)

Example:

ezscr new helloWorld

Returns:

Creating dir /full/path/to/config
Creating file /full/path/to/config/config.yaml
Creating dir /full/path/to/config/secret
Creating script /full/path/to/config/helloWorld.nims

Configs

To edit the secret and aliases, just open the config.yaml file.

pack: Pack the scripts

After you finished the scripting, you need to pack all the scripts into a encrypted JSON (default name is data.enc)

To do that, just run

ezscr pack

Returns:

Packing /full/path/to/config/helloWorld.nims
Encoding data

run: Run script

To run the script you will need:

  • exscr binary
  • data.enc with script(s) inside

The configs dir you cannot delete because there's no decrypt command.

To run a script just:

ezscr run helloWorld

cleanLib: Delete all the lib created (in temp)

ezscr clean_lib

Features

Full access to all std lib (supported by Nimscript)

Thanks to the nimscripter lib, the scripts has full support to Nim's std lib

Example working with json

from std/json import parseJson, `{}`, getStr

proc main*(params: seq[string]): bool =
  ## This example fetches a json, parse it and get specific value
  let
    node = parseJson "https://dummyjson.com/products/1".httpGet.body
    title = node{"title"}.getStr
    description = node{"description"}.getStr

  echo title
  echo description

  result = title.len > 0 # Return success if there's a title

Extended lib (undocumented yet)

There's more procs than just std, you can download files with just one command, encrypt and decrypt strings (using same algorithm that is encoded the data.enc) and more

Soon I will finish the documentation

Static download

Want to import some remote file? No problems!

Just download it by using this syntax:

# Note the mandatory space after `>`
#> staticDownload "https://example.com/file.txt"

and import it, see the full example:

#> staticDownload "https://git.ozzuu.com/thisago/util/raw/branch/master/src/util/forStr.nim"
import forStr

proc main*(params: seq[string]): bool =
  echo "Hello John Doe!".between("llo ", " Do") # -> John

Limitations:

  • You cannot specify the destination
  • The URL cannot contains double quotes (")
  • One download per line
  • Ignores any download error and proceeds

TODO

  • Add possibility to add multiple aliases to same script
  • Add a possibility to reuse same encryption key (instead compilation time), maybe provide in nimble file
  • Add option to run again x times until the raised exception stop to be raise in run command
  • Add option to process the main return (bool) false as a raised error and run the script until returns true
  • Add optional custom destination fot staticDownload downloads
  • Add possibility to import pkg modules from nimble package list
  • Add listed and unlisted scripts (now all is unlisted)
  • Add --help in scripts, extract from main proc doc comment
  • Add static files in config to pack it and with a internal proc call, access the file
  • Add a lib extension file like config/lib.nim to add more internal procs to the Nimscript scope, adding procs that cannot be ran in Nimscript, like ddl handling

License

MIT

ezscr's People

Contributors

thisago avatar

Stargazers

 avatar  avatar  avatar

Watchers

 avatar

ezscr's Issues

Show the dir where the Nim lib is placed

Is your feature request related to a problem? Please describe.
In windows server have multiple temp directories

Describe the solution you'd like
Show the dir where the lib is placed

Describe alternatives you've considered
Show at commands:

  • setup_lib
  • clean_lib

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.