Skip to content

Commit

Permalink
Initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
mschmidtkorth committed Feb 19, 2020
2 parents 6c3e372 + 03ffdad commit fd91a63
Showing 1 changed file with 8 additions and 8 deletions.
16 changes: 8 additions & 8 deletions SFDX.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ async def main(connection):
@iterm2.RPC
async def displayExpirationDate(session_id):
await component.async_open_popover(session_id, "<p style='font-family: Arial'>Retrieving org expiration date... <em>(wait)</em></p>", iterm2.Size(300, 30))

from subprocess import Popen, PIPE
import json
p = Popen(['sfdx force:org:display --targetusername=' + aliasOrUsername + ' --json'], stdin = PIPE, stdout = PIPE, stderr = PIPE, universal_newlines = True, shell = True)
Expand All @@ -30,18 +30,18 @@ async def displayExpirationDate(session_id):
expiration += '(expired)'
elif stdout:
expiration += 'Never - org is a sandbox.'

await component.async_open_popover(session_id, "<p style='font-family: Arial'>The scratch org expires on: <strong>" + expiration + '</strong></p>', iterm2.Size(350, 30))

knobs = [iterm2.CheckboxKnob("Enable expiration date", False, "showExpirationDate")]
component = iterm2.StatusBarComponent(short_description = "SFDX Status", detailed_description = "Provides status info for SFDX project folders", knobs = knobs, exemplar = u"\u2601 SFDC-1234 [email protected]", update_cadence = None, identifier = "com.msk.sfdx")

@iterm2.StatusBarRPC
async def coro(knobs, path = iterm2.Reference("path"), cwd = iterm2.Reference("user.currentDir?")):
import os
import json
from pathlib import Path

currentDir = path
if 'force-app' in currentDir: # User is in subdirectory
currentDir = currentDir.split('force-app')[0] # Get root directory of project folder
Expand All @@ -52,18 +52,18 @@ async def coro(knobs, path = iterm2.Reference("path"), cwd = iterm2.Reference("u
config = json.load(configFile)
global aliasOrUsername
aliasOrUsername = config['defaultusername']

# Retrieve username for alias
with open(os.environ['HOME'] + '/.sfdx/alias.json') as aliasFile:
alias = json.load(aliasFile)

if 'defaultusername' in config and 'orgs' in alias:
return u'\u2601 ' + config['defaultusername'] + u' \u2022 ' + alias['orgs'][config['defaultusername']]
else:
return u'\u2601' # Some error occurred, e.g. file not found or wrong content
else:
return u'\u2601' # No SFDX directory

await component.async_register(connection, coro, timeout = 15.0, onclick = displayExpirationDate)


Expand Down

0 comments on commit fd91a63

Please sign in to comment.