Skip to content

How To Build a Module

CurlyMoo edited this page Mar 2, 2013 · 4 revisions

###Structure An xbian-config module consists of three files.

dialogs This file contains the logic of creating the GUI dialogs. Every dialog should be represented by a separate function. Every logic inside the dialog functions should contain only that much logic as needed to create a GUI. Examples are creating the tables, (vertical) centering, word-wrapping etc.

The function naming of a dialog function should be as verbose as possible so it is clear to developers what the function of the dialog is. The suffix of a dialog function should contain the three letters Dlg()

functions This file contains all the function to get the job of this module done. Every single logic should contain a single function. Examples are updates, inserting, deleting stuff. This makes it easier for developers to expand or modify module logic.

The naming of a module should be as verbose as possible to the functionality of the module is clear. The suffix of a these functions should contain the the two letters Fn()

main The main file of a module combines the logic of a module with the GUI or CLI. The header of a module should at least contain the following:
- #!/bin/bash
- A copyright notice with the developers (nick)name and email address
- A GPL header
- Global variables
-- All CLI arguments of the module as an array called ARGUMENTS
-- All other global variables for inside the module
- Include files
-- functions
-- dialogs
-- All other functions like xbian-config wide classes

The second part of the module should at least contain two functions called showGUIFn() and showCMDFn(). The showGUIFn will be called when xbian-config is opened with the GUI enabled. The showCMDFn is called when xbian-config is called with an command line argument.

###GUI The GUI contains at least one function called showGUIFn. An important aspect of the GUI is that the user should be able to go back to a previous dialog or the main menu. Sometimes more GUI control functions are needed inside the main file to achieve this behavior.

###CLI The CLI exists essentially of one big condition with some logic for all CLI arguments supported by the module. The first argument given to this function will be the argument that this module is called with e.g. xbian-config network select. This means that xbian-config will open the network module and transfers the second argument to the showCMDFn. The first argument of the showCMDFn will then be select. Developers can use this first argument to know what logic the user wants executed. Return codes or values should be returned by calling an echo instead of a return. The main function of the CLI logic is combining the different functions of a module in a functional way.

Every argument following the second argument of xbian-config or the first argument of the module will be values needed by a specific function. The requirement of a module are as followed.

Return codes The standard return codes are:
- 1: The logic of the function was successfull
- 0: The logic of the function failed
Depending on the module, additional return codes are needed to exactly know what went wrong. Make sure that additional failure codes are numbers smaller than 0 and additional succes codes are numbers bigger than 0.

Checks Every function should at least contain the following checks:
- Was the module called with the correct number of arguments?
- Were the arguments of a correct types?

Returned values If a function needs to return values/output, make sure the output has a developer friendly markup. This means no unnessecary capitals, symbols, special characters etc. Every part of the output should be functional.

Clone this wiki locally