Skip to content

Commit

Permalink
Merge pull request #11 from essentialkaos/develop
Browse files Browse the repository at this point in the history
Version 1.1.0
  • Loading branch information
andyone authored Jun 10, 2019
2 parents 3d6dba4 + 4cc6e56 commit 6352547
Show file tree
Hide file tree
Showing 5 changed files with 58 additions and 1 deletion.
24 changes: 24 additions & 0 deletions COOKBOOK.md
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@
* [`lib-loaded`](#lib-loaded)
* [`lib-header`](#lib-header)
* [`lib-config`](#lib-config)
* [`lib-exist`](#lib-exist)
* [Examples](#examples)

## Recipe Syntax
Expand Down Expand Up @@ -1498,6 +1499,29 @@ command "-" "Check environment"

<br/>

##### `lib-exist`

Checks if library file is exist in libraries directory.

**Syntax:** `lib-exist <filename>`

**Arguments:**

* `filename` - Library file name (_String_)

**Negative form:** Yes

**Example:**

```yang
command "-" "Check environment"
lib-exist libc.so.1
lib-exist libc_nonshared.a
```

<br/>

## Examples

```yang
Expand Down
31 changes: 31 additions & 0 deletions action/libs.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,12 @@ var headersDirs = []string{
}

var libDirs = []string{
"/lib",
"/lib64",
"/usr/lib",
"/usr/lib64",
"/usr/local/lib",
"/usr/local/lib64",
}

// ////////////////////////////////////////////////////////////////////////////////// //
Expand Down Expand Up @@ -113,6 +117,33 @@ func LibConfig(action *recipe.Action) error {
return nil
}

// LibExist is action processor for "lib-exist"
func LibExist(action *recipe.Action) error {
lib, err := action.GetS(0)

if err != nil {
return err
}

var hasLib bool

for _, libDir := range libDirs {
if fsutil.IsExist(libDir + "/" + lib) {
hasLib = true
break
}
}

switch {
case !action.Negative && !hasLib:
return fmt.Errorf("Library file %s not found on the system", lib)
case action.Negative && hasLib:
return fmt.Errorf("Library file %s found on the system", lib)
}

return nil
}

// ////////////////////////////////////////////////////////////////////////////////// //

func isLibLoaded(glob string) (bool, error) {
Expand Down
2 changes: 1 addition & 1 deletion cli/cli.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ import (
// Application info
const (
APP = "bibop"
VER = "1.0.0"
VER = "1.1.0"
DESC = "Utility for testing command-line tools"
)

Expand Down
1 change: 1 addition & 0 deletions cli/executor/executor.go
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,7 @@ var handlers = map[string]action.Handler{
"lib-loaded": action.LibLoaded,
"lib-header": action.LibHeader,
"lib-config": action.LibConfig,
"lib-exist": action.LibExist,
}

var temp *tmp.Temp
Expand Down
1 change: 1 addition & 0 deletions recipe/tokens.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ const (
ACTION_LIB_LOADED = "lib-loaded"
ACTION_LIB_HEADER = "lib-header"
ACTION_LIB_CONFIG = "lib-config"
ACTION_LIB_EXIST = "lib-exist"
)

// ////////////////////////////////////////////////////////////////////////////////// //
Expand Down

0 comments on commit 6352547

Please sign in to comment.