Skip to content

Commit

Permalink
Improve flag support in install.py after #254 (#255)
Browse files Browse the repository at this point in the history
  • Loading branch information
ddworken authored Oct 7, 2024
1 parent e55694d commit d22bba2
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 11 deletions.
2 changes: 0 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -160,8 +160,6 @@ hishtory config-set filter-duplicate-commands true
If you don't need the ability to sync your shell history, you can install hiSHtory in offline mode:

```sh
curl https://hishtory.dev/install.py | HISHTORY_OFFLINE=true python3 -
# or
curl https://hishtory.dev/install.py | python3 - --offline
```

Expand Down
5 changes: 3 additions & 2 deletions backend/web/landing/www/install.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,9 @@ def get_executable_tmpdir():
cmd = tmpFilePath + ' install'
if os.environ.get('HISHTORY_OFFLINE'):
cmd += " --offline"
if len(sys.argv) > 1:
cmd += " " + " ".join(sys.argv[1:])
additional_flags = [flag for flag in sys.argv[1:] if flag.startswith("-") and flag != "-"]
if additional_flags:
cmd += " " + " ".join(additional_flags)
exitCode = os.system(cmd)
os.remove(tmpFilePath)
if exitCode != 0:
Expand Down
16 changes: 9 additions & 7 deletions client/client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1063,18 +1063,16 @@ func TestInstallViaPythonScriptWithCustomHishtoryPath(t *testing.T) {
require.NoError(t, err)
require.NoError(t, os.RemoveAll(path.Join(homedir, altHishtoryPath)))

testInstallViaPythonScriptChild(t, zshTester{})
testInstallViaPythonScriptChild(t, zshTester{}, Online)
}

func TestInstallViaPythonScriptInOfflineMode(t *testing.T) {
markTestForSharding(t, 1)
defer testutils.BackupAndRestore(t)()
defer testutils.BackupAndRestoreEnv("HISHTORY_OFFLINE")()
os.Setenv("HISHTORY_OFFLINE", "1")
tester := zshTester{}

// Check that installing works
testInstallViaPythonScriptChild(t, tester)
testInstallViaPythonScriptChild(t, tester, Offline)

// And check that it installed in offline mode
out := tester.RunInteractiveShell(t, `hishtory status -v`)
Expand All @@ -1083,14 +1081,14 @@ func TestInstallViaPythonScriptInOfflineMode(t *testing.T) {

func testInstallViaPythonScript(t *testing.T, tester shellTester) {
defer testutils.BackupAndRestore(t)()
testInstallViaPythonScriptChild(t, tester)
testInstallViaPythonScriptChild(t, tester, Online)

// And check that it installed in online mode
out := tester.RunInteractiveShell(t, `hishtory status -v`)
require.Contains(t, out, "\nSync Mode: Enabled\n")
}

func testInstallViaPythonScriptChild(t *testing.T, tester shellTester) {
func testInstallViaPythonScriptChild(t *testing.T, tester shellTester, onlineStatus OnlineStatus) {
if !testutils.IsOnline() {
t.Skip("skipping because we're currently offline")
}
Expand All @@ -1099,7 +1097,11 @@ func testInstallViaPythonScriptChild(t *testing.T, tester shellTester) {
defer testutils.BackupAndRestoreEnv("HISHTORY_TEST")()

// Install via the python script
out := tester.RunInteractiveShell(t, `curl https://hishtory.dev/install.py | python3 -`)
additionalFlags := " "
if onlineStatus == Offline {
additionalFlags = "--offline"
}
out := tester.RunInteractiveShell(t, `curl https://hishtory.dev/install.py | python3 -`+additionalFlags)
require.Contains(t, out, "Succesfully installed hishtory")
r := regexp.MustCompile(`Setting secret hishtory key to (.*)`)
matches := r.FindStringSubmatch(out)
Expand Down

0 comments on commit d22bba2

Please sign in to comment.