tushar_ecmc
tushar_ecmc

Reputation: 188

New to python fabric and not able to run basic code

I have a basic code which doesn't run:

def hello():
    print("uptime")

When I run the following command in terminal fab hello

I get this error:

No idea what 'hello' is!

Upvotes: 0

Views: 998

Answers (3)

Vignesh Pandian
Vignesh Pandian

Reputation: 11

Instead of using this,

from fabric import task
@task
def hello():
  print("uptime")

fabric has been expecting like this,

from fabric import task
@task
def hello(c):
    print("uptime")

passing an argument (c) as the first argument for each task since Fabric expects the Connection object as the first argument

Hope this solves for someone

Upvotes: 1

Rounak
Rounak

Reputation: 806

The issue is that the new fabric task method (as discussed here - http://docs.fabfile.org/en/1.14/usage/tasks.html) is to use the @task decorator. The equivalent example for your code is:

from fabric import task

@task
def hello():
  print("uptime")

Running fab hello should yield the expected output.

Source: https://github.com/fabric/fabric/issues/1854#issuecomment-414639606

Upvotes: 2

Prof.AI
Prof.AI

Reputation: 107

You most likely have to type:

fab hello()

or

$ fab hello

Upvotes: -2

Related Questions