« get me outta code hell

cli args (bass boost ur music) - mtui - Music Text User Interface - user-friendly command line music player
about summary refs log tree commit diff
path: root/index.js
diff options
context:
space:
mode:
authorFlorrie <towerofnix@gmail.com>2020-02-15 22:13:53 -0400
committerFlorrie <towerofnix@gmail.com>2020-02-15 22:15:15 -0400
commit48ed5168d477fe11fe4f21ae104e3750935b0943 (patch)
treec0d9260246933d180a2fa5405da8e66e9c484705 /index.js
parentfd09d0196f8db2102f9364a56f3075bf2cd93c88 (diff)
cli args (bass boost ur music)
$ mtui --player sox --player-options bass +25 \;
Diffstat (limited to 'index.js')
-rwxr-xr-xindex.js39
1 files changed, 34 insertions, 5 deletions
diff --git a/index.js b/index.js
index bb0daee..c40bbb9 100755
--- a/index.js
+++ b/index.js
@@ -3,6 +3,8 @@
 // omg I am tired of code
 
 const { getAllCrawlersForArg } = require('./crawlers')
+const { getPlayer } = require('./players')
+const { parseOptions } = require('./general-util')
 const AppElement = require('./ui')
 const Backend = require('./backend')
 const TelnetServer = require('./telnet-server')
@@ -50,7 +52,36 @@ process.on('unhandledRejection', error => {
 })
 
 async function main() {
-  const backend = new Backend()
+  const playlistSources = []
+
+  const options = await parseOptions(process.argv.slice(2), {
+    'player': {
+      type: 'value',
+      async validate(playerName) {
+        if (await getPlayer(playerName)) {
+          return true
+        } else {
+          return 'a known player identifier'
+        }
+      }
+    },
+    'player-options': {
+      type: 'series'
+    },
+    [parseOptions.handleDashless](option) {
+      playlistSources.push(option)
+    }
+  })
+
+  if (options['player-options'] && !options['player']) {
+    console.error('--player must be specified in order to use --player-options')
+    process.exit(1)
+  }
+
+  const backend = new Backend({
+    playerName: options['player'],
+    playerOptions: options['player-options']
+  })
 
   const result = await backend.setup()
   if (result.error) {
@@ -93,10 +124,8 @@ async function main() {
   })
 
   const loadPlaylists = async () => {
-    for (let i = 2; i < process.argv.length; i++) {
-      if (!process.argv[i].startsWith('--')) {
-        await appElement.handlePlaylistSource(process.argv[i], true)
-      }
+    for (const source of playlistSources) {
+      await appElement.handlePlaylistSource(source, true)
     }
   }