Skip to content

Commit

Permalink
added argos support
Browse files Browse the repository at this point in the history
  • Loading branch information
infeeeee committed Jul 9, 2019
1 parent d435c6a commit fa97ace
Show file tree
Hide file tree
Showing 3 changed files with 108 additions and 64 deletions.
7 changes: 5 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ Integration:
- [x] Portable executable for all three platforms
- [ ] Installer for windows
- [ ] Generate output for Rainmeter (Windows) (Just like [kimai-cmd](https://github.com/infeeeee/kimai-cmd))
- [ ] Generate output for Argos/Kargos/Bitbar (Gnome, Kde, Mac)
- [x] Generate output for Argos/Kargos/Bitbar (Gnome, Kde, Mac). More info here: [kimai2-cmd-argos](https://github.com/infeeeee/kimai2-cmd-argos)

## Installation

Expand Down Expand Up @@ -86,16 +86,19 @@ Options:
-V, --version output the version number
-v, --verbose verbose, longer logging
-i, --id show id of elements when listing
-b, --argosbutton argos/bitbar button output
-a, --argos argos/bitbar output
-h, --help output usage information
Commands:
start [project] [activity] start selected project and activity
restart [id] restart selected measurement
stop stop all measurements
stop [id] stop all or selected measurement measurements, [id] is optional
list-active list active measurements
list-recent list recent measurements
list-projects list all projects
list-activities list all activities
url prints the url of the server
```

Project and activity names are case insensitive. If your project or activity name contains a space, wrap it in double or single quotes. This example starts project named `foo` with activity named `bar bar`:
Expand Down
163 changes: 102 additions & 61 deletions kimai2-cmd.js
Original file line number Diff line number Diff line change
Expand Up @@ -361,6 +361,88 @@ function kimaiList(settings, endpoint, print = false, options = false) {
})
}

/**
* Prints list to terminal
*
* @param {array} arr Items to list
* @param {string} endpoint for selecting display layout
* @param {object} options
* options.printId: print ids with list
* options.verbose
*/
function printList(arr, endpoint, options = false) {
const verbose = options.verbose || false
const printId = options.printId || false
if (verbose) {
console.log()
if (arr.length > 1) {
console.log(arr.length + ' results:')
} else if (arr.length == 0) {
console.log('No results')
} else {
console.log('One result:')
}
}
//no result for scripts:
if (arr.length == 0) {
if (program.argos) {
console.log('No active measurements')
}
if (program.argosbutton) {
console.log("Kimai2")
}
}
for (let i = 0; i < arr.length; i++) {
const element = arr[i];

if (endpoint == 'projects' || endpoint == 'activities') {
if (verbose) {
console.log((i + 1) + ':', element.name, '(id:' + element.id + ')')
} else if (printId) {
console.log(element.id + ':', element.name)
} else {
console.log(element.name)
}

} else { //measurements
if (verbose) {
if (arr.length > 1) {
console.log((i + 1) + ":")
}
console.log(' Id: ' + element.id)
console.log(' Project: ' + element.project.name, '(id:' + element.project.id + ')')
console.log(' Customer: ' + element.project.customer.name, '(id:' + element.project.customer.id + ')')
console.log(' Activity: ' + element.activity.name, '(id:' + element.activity.id + ')')
console.log(' Begin: ' + element.begin)

if (moment(element.end).isValid()) {
//finished measurements:
let dur = moment.duration(moment(element.end).diff(moment(element.begin)))
console.log(' Duration: ' + dur.hours() + ':' + dur.minutes())
} else {
//active measurements:
let dur = moment.duration(moment().diff(moment(element.begin)))
console.log(' Duration: ' + dur.hours() + ':' + dur.minutes())
}

} else if (printId) {
console.log(element.id + ':', element.project.name, '|', element.activity.name)
} else if (program.argos || program.argosbutton) {
if (endpoint == 'timesheets/recent') {
console.log('--' + element.project.name + ',', element.activity.name, '|', 'bash="kimai restart', element.id, '" terminal=false refresh=true')
} else if (endpoint == 'timesheets/active') {
let dur = moment.duration(moment().diff(moment(element.begin)))
console.log(dur.hours() + ':' + dur.minutes(), element.project.name + ',', element.activity.name, '|', 'bash="kimai stop', element.id, '" terminal=false refresh=true')
}
} else {
console.log(element.project.name, '|', element.activity.name)
}
}
}
console.log()
}


/**
* Interactive ui: select measurement from a list of measurements
* @param {} thelist
Expand Down Expand Up @@ -436,58 +518,6 @@ function uiAutocompleteSelect(thelist, message) {
}


/**
* Prints list to terminal
*
* @param {array} arr Items to list
* @param {string} endpoint for selecting display layout
* @param {boolean} verbose
*/
function printList(arr, endpoint, options = false) {
verbose = options.verbose || false
printId = options.printId || false
if (verbose) {
console.log()
if (arr.length > 1) {
console.log(arr.length + ' results:')
} else if (arr.length == 0) {
console.log('No results')
} else {
console.log('One result:')
}
}
for (let i = 0; i < arr.length; i++) {
const element = arr[i];

if (endpoint == 'projects' || endpoint == 'activities') {
if (verbose) {
console.log((i + 1) + ':', element.name, '(id:' + element.id + ')')
} else if (printId) {
console.log(element.id + ':', element.name)
} else {
console.log(element.name)
}

} else { //measurements
if (verbose) {
if (arr.length > 1) {
console.log((i + 1) + ":")
}
console.log(' Id: ' + element.id)
console.log(' Project: ' + element.project.name, '(id:' + element.project.id + ')')
console.log(' Customer: ' + element.project.customer.name, '(id:' + element.project.customer.id + ')')
console.log(' Activity: ' + element.activity.name, '(id:' + element.activity.id + ')')
console.log()
} else if (printId) {
console.log(element.id + ':', element.project.name, '|', element.activity.name)
} else {
console.log(element.project.name, '|', element.activity.name)
}
}
}
console.log()
}

/**
* Finds settings file path
*
Expand All @@ -496,13 +526,14 @@ function printList(arr, endpoint, options = false) {
* @returns false: If no settings found
*/
function iniPath(verbose) {
//different settings.ini path for developement and pkg version
//different settings.ini path for developement and pkg and windows installer version
const iniRoot = [
path.dirname(process.execPath),
__dirname,
path.join(appdata, '/kimai2-cmd')
__dirname
]

if (appdata) { iniRoot.push(path.join(appdata, '/kimai2-cmd')) }

if (verbose) {
console.log('Looking for settings.ini in the following places:')
console.log(iniRoot)
Expand Down Expand Up @@ -621,8 +652,9 @@ program
.description(pjson.description + '. For interactive mode start without any commands. To generate settings file start in interactive mode!')
.option('-v, --verbose', 'verbose, longer logging', false)
.option('-i, --id', 'show id of elements when listing', false)
// .option('-r, --rainmeter', 'generate rainmeter files')
// .option('-a, --argos', 'argos/bitbar output')
// .option('-r, --rainmeter', 'generate rainmeter files')
.option('-b, --argosbutton', 'argos/bitbar button output')
.option('-a, --argos', 'argos/bitbar output')

program.command('start [project] [activity]')
.description('start selected project and activity')
Expand Down Expand Up @@ -651,12 +683,12 @@ program.command('restart [id]')
})
})

program.command('stop')
.description('stop all measurements')
.action(function () {
program.command('stop [id]')
.description('stop all or selected measurement measurements, [id] is optional')
.action(function (measurementId) {
checkSettings()
.then(settings => {
kimaiStop(settings)
kimaiStop(settings, measurementId)
})
})

Expand Down Expand Up @@ -696,6 +728,15 @@ program.command('list-activities')
})
})

program.command('url')
.description('prints the url of the server')
.action(function () {
checkSettings()
.then(settings => {
console.log(settings.serversettings.kimaiurl)
})
})

// program.command('debug')
// .description('debug snapshot filesystem. If you see this you are using a developement build')
// .action(function () {
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "kimai2-cmd",
"version": "0.1.0",
"version": "0.2.0",
"description": "Command line client for Kimai2",
"main": "kimai2-cmd.js",
"bin": "kimai2-cmd.js",
Expand Down

0 comments on commit fa97ace

Please sign in to comment.