All Projects → macmade → Shellkit

macmade / Shellkit

Licence: mit
Objective-C framework for running shell scripts.

Programming Languages

shell
77523 projects

Projects that are alternatives of or similar to Shellkit

Netclient Ios
Versatile HTTP Networking in Swift
Stars: ✭ 117 (+40.96%)
Mutual labels:  task, framework
Commands
Java Command Dispatch Framework - (Bukkit, Spigot, Paper, Sponge, Bungee, JDA, Velocity supported, generically usable anywhere)
Stars: ✭ 266 (+220.48%)
Mutual labels:  command, framework
Typin
Declarative framework for interactive CLI applications
Stars: ✭ 126 (+51.81%)
Mutual labels:  command, framework
Cargo Make
Rust task runner and build tool.
Stars: ✭ 895 (+978.31%)
Mutual labels:  task, travis
Kommander Ios
A lightweight, pure-Swift library for manage the task execution in different threads. Through the definition a simple but powerful concept, Kommand.
Stars: ✭ 167 (+101.2%)
Mutual labels:  command, task
Aruba
Test command-line applications with Cucumber-Ruby, RSpec or Minitest. The most up to date documentation can be found on Cucumber.Pro (https://app.cucumber.pro/projects/aruba)
Stars: ✭ 900 (+984.34%)
Mutual labels:  command, framework
Setl
A simple Spark-powered ETL framework that just works 🍺
Stars: ✭ 79 (-4.82%)
Mutual labels:  framework
Enduro2d
Yet another 2d game engine of dreams (work in progress)
Stars: ✭ 82 (-1.2%)
Mutual labels:  framework
Transformers
基于 JavaScript 的组件化开发框架,如果你想以搭积木的方式开发项目,那就试试 Transformers 框架吧~
Stars: ✭ 78 (-6.02%)
Mutual labels:  framework
Kales
Kotlin on Rails
Stars: ✭ 78 (-6.02%)
Mutual labels:  framework
Tui.calendar
🍞📅A JavaScript calendar that has everything you need.
Stars: ✭ 9,537 (+11390.36%)
Mutual labels:  task
Typetron
Modern Node.js framework for creating fully-featured apps
Stars: ✭ 82 (-1.2%)
Mutual labels:  framework
Openmod
OpenMod .NET Plugin Framework
Stars: ✭ 81 (-2.41%)
Mutual labels:  framework
Forge
Basic experiment framework for tensorflow.
Stars: ✭ 79 (-4.82%)
Mutual labels:  framework
Homie Esp8266
💡 ESP8266 framework for Homie, a lightweight MQTT convention for the IoT
Stars: ✭ 1,241 (+1395.18%)
Mutual labels:  framework
Neo
Create blazing fast multithreaded Web Apps
Stars: ✭ 1,219 (+1368.67%)
Mutual labels:  framework
Universal.css
The only CSS you will ever need
Stars: ✭ 1,247 (+1402.41%)
Mutual labels:  framework
Toruk
Go web 开发脚手架
Stars: ✭ 78 (-6.02%)
Mutual labels:  framework
Duality
a 2D Game Development Framework
Stars: ✭ 1,231 (+1383.13%)
Mutual labels:  framework
Framework
The Tastphp Framework Core
Stars: ✭ 82 (-1.2%)
Mutual labels:  framework

ShellKit

Build Status Coverage Status Issues Status License Contact
Donate-Patreon Donate-Gratipay Donate-Paypal

About

Objective-C framework for running shell scripts.

Terminal

Documentation

Documentation and API reference can be found at: http://doc.xs-labs.com/ShellKit/

Code Examples

ShellKit provides a test executable.
For complete examples, please take a look at the source code.

Shell informations

Various shell informations, like paths for commands, can be retrieved using the SKShell class:

[ [ SKShell currentShell ] commandIsAvailable: @"xcodebuild" ]

NSString * path = [ [ SKShell currentShell ] pathForCommand: @"xcodebuild" ]

Running simple commands

Arbitrary shell commands can be run using the SKShell class.
Note that commands are executed using the shell defined in the SHELL environment variable, invoked as a login shell.
Data for stdin can be provided; stdout and stderr can be retrieved.

[ [ SKShell currentShell ] runCommand: @"ls -al"
                           completion: ^( int status, NSString * output, NSString * error )
    {
        NSLog( @"%i", status );
        NSLog( @"%@", output );
        NSLog( @"%@", error );
    }
];

Running shell script tasks

A shell command can by run by using the SKTask object:

SKTask * task;

task = [ SKTask taskWithShellScript: @"ls -al" ];

[ task run ];

The task is run synchronously, and its output, if any, will be automatically printed to stdout.

The task will print the executed command prior to running, and print a status message once it's terminated, along with the elapsed time:

[ ShellKit ]> 🚦  Running task: ls -al
total 536
drwxr-xr-x  5 macmade  staff     170 May 11 23:49 .
[email protected] 4 macmade  staff     136 May 11 22:18 ..
-rwxr-xr-x  1 macmade  staff  124624 May 11 23:49 ShellKit-Test
drwxr-xr-x  7 macmade  staff     238 May 11 23:48 ShellKit.framework
-rw-r--r--  1 macmade  staff  143936 May 11 23:48 libShellKit-Static.a
[ ShellKit ]> ✅  Task completed successfully (63 ms)

A task can have sub-tasks, to try to recover from a failure:

SKTask * task;

task = [ SKTask taskWithShellScript: @"false" recoverTask: [ SKTask taskWithShellScript: @"true" ] ];

[ task run ];

Here, the false task will obviously fail, but it will then execute the true task, set as recovery.
As true will succeed, the false task will also succeed:

[ ShellKit ]> 🚦  Running task: false
[ ShellKit ]> ⚠️  Task failed - Trying to recover...
[ ShellKit ]> 🚦  Running task: true
[ ShellKit ]> ✅  Task completed successfully (66 ms)
[ ShellKit ]> ✅  Task recovered successfully (66 ms)

Optional tasks

A task can be marked as optional by using the SKOptionalTask.
In such a case, the task will succeed, regardless of its exit status:

SKOptionalTask * task;
            
task = [ SKOptionalTask taskWithShellScript: @"false" ];

[ task run ];
[ ShellKit ]> 🚦  Running task: false
[ ShellKit ]> ❌  Error - Task exited with status 1
[ ShellKit ]> ✅  Task is marked as optional - Not failing

Running task groups

Multiple tasks can be grouped in a SKTaskGroup object:

SKTask      * t1;
SKTask      * t2;
SKTaskGroup * group;

t1    = [ SKTask taskWithShellScript: @"true" ];
t2    = [ SKTask taskWithShellScript: @"true" ];
group = [ SKTaskGroup taskGroupWithName: @"task-group" tasks: @[ t1, t2 ] ];
        
[ group run ];

The group will try to run each task.
If a task fails, the whole group will also fail.

[ ShellKit ]> [ task-group ]> 🚦  Running 2 tasks
[ ShellKit ]> [ task-group ]> [ #1 ]> 🚦  Running task: true
[ ShellKit ]> [ task-group ]> [ #1 ]> ✅  Task completed successfully (64 ms)
[ ShellKit ]> [ task-group ]> [ #2 ]> 🚦  Running task: true
[ ShellKit ]> [ task-group ]> [ #2 ]> ✅  Task completed successfully (65 ms)
[ ShellKit ]> [ task-group ]> ✅  2 tasks completed successfully (132 ms)

Running task groups within task groups

A task group may also contain other task groups:

SKTask      * t1;
SKTask      * t2;
SKTaskGroup * g1;
SKTaskGroup * g2;

t1 = [ SKTask taskWithShellScript: @"true" ];
t2 = [ SKTask taskWithShellScript: @"true" ];
g1 = [ SKTaskGroup taskGroupWithName: @"child-group" tasks: @[ t1, t2 ] ];
g2 = [ SKTaskGroup taskGroupWithName: @"parent-group" tasks: @[ g1 ] ];
        
[ g2 run ];

The hierarchy of groups will be reflected by the prompt, like:

[ ShellKit ]> [ parent-group ]> [ #1 ]> [ child-group ]> [ #1 ]> 🚦  Running task: true

Note that task groups can also run custom classes, as long as they conform to the SKRunableObject protocol.

Variables substitution

A task may contain variables, that will be substituted when running.
A variable has the following form:

%{name}%

The variable name may contain letters from A to Z (uppercase or lowercase) and numbers from 0 to 9.

Variables are passed using the run: method of SKTask and SKTaskGroup.

SKTask * task;

task = [ SKTask taskWithShellScript: @"ls %{args}% %{dir}%" ];

[ task run: @{ @"args" : @"-al", @"dir" : @"/usr" } ];

In the example above, the executed script will be: ls -al /usr.

If no value is provided for a variable, the task will fail:

SKTask * task;

task = [ SKTask taskWithShellScript: @"echo %{hello}% %{foo}% %{bar}%" ];

[ task run: @{ @"hello" : @"hello, world" } ];
[ ShellKit ]> 🚦  Running task: echo hello, world %{foo}% %{bar}%
[ ShellKit ]> ⚠️  No value provided value for variable: foo
[ ShellKit ]> ⚠️  No value provided value for variable: bar
[ ShellKit ]> ❌  Error - Script contains unsubstituted variables

Printing messages

Messages can be printed very easily.
For this purpose, the SKShell class provides several methods, like the following one:

- ( void )printMessage: ( NSString * )format
          status:       ( SKStatus )status
          color:        ( SKColor )color,
                        ...;

The status represents an optional icon.
Colors can also be used, if the terminal supports it.

As an example:

[ [ SKShell currentShell ] printMessage: @"hello, %@"
                           status:       SKStatusDebug
                           color:        SKColorCyan,
                                         @"world"
];

will produce:

🚸 hello, world

Customising prompt

The prompt can be customised to reflect the hierarchy of the invoked commands.

For instance:

[ SKShell currentShell ].promptParts = @[ @"foo", @"bar" ];

Then, every printed message will be prefixed by:

[ foo ]> [ bar ]> ... message ...

License

ShellKit is released under the terms of the MIT license.

Repository Infos

Owner:          Jean-David Gadina - XS-Labs
Web:            www.xs-labs.com
Blog:           www.noxeos.com
Twitter:        @macmade
GitHub:         github.com/macmade
LinkedIn:       ch.linkedin.com/in/macmade/
StackOverflow:  stackoverflow.com/users/182676/macmade
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].